What is a NullReferenceException in .NET?
- by John Saunders
(I'm creating this separate question and answer because every question we get on NullReferenceException is really the same)
I have some code and when it executes, it throws a NullReferenceException, saying, "Object reference not set to an instance of an object.".
What does this mean, and what can I do about it?
Note again, that this is a question meant to focus answers to the canonical "what is a NullReferenceException and why did I get one" question. I do know what a NullReferenceException is, as my answer below demonstrates.