Pro tip: until nullable reference types hit primetime, use JetBrains.Annotations and add NotNull / CanBeNull attributes to all reference-type fields, properties, parameters and return types. As long as you run ReSharper and fix all warnings, you should never have a NullReferenceException again.
Even better - install ReCommended extensions for ReSharper, and make it a warning to not annotate reference types. Your code should now be almost NullReferenceException-proof.
Enjoy never worrying about this error again.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.