What is the meaning of NullReferenceException

c#

Solution

It means you've tried to access a member of something that isn't there:

string s = null;
int i = s.Length; // boom

Just fix the thing that is null. Either make it non-null, or perform a null-test first.

There is also a corner-case here related to `Nullable<T>`, generics and the `new` generic constraint - a bit unlikely though (but heck, I hit this issue!).

Problem

Possible Duplicate: What is a NullReferenceException in .NET? For example, "`System.NullReferenceException` was unhandled", with Message "Object reference not set to an instance of an object." What is the meaning of this exception, and how can it be solved?

Original source

Related problems