Well, since I was getting a ridiculous number of down votes on my other question, here it is again in a more blunt and less lighthearted fashion:
null
represent the lack of an object; and
- all strings are objects; thus
- there is no string, of any length, which is
null
; thus
- an empty string is never
null
.
That's it, nothing more. Examine the stack-trace and/or attach a debugger to find out where the null
(which is not an empty string) is coming from.
The exception is the result of using expr.somePropertyFieldOrMethod
where expr
evaluates to null
1 hence the Null Reference Exception.
It is the job of you, the developer, to find out which expr
was null
instead of waiting to see what others suggest might be wrong. As such, I am closing this as "too localized" after answering the question in the title, which is the only question present.
(As in my previous answer, I note that textBoxVersionInfo
being null
could cause this exception, even when VersionInfo == ""
is true. The other alternative is, of course, that that VersionInfo
does not represent the empty string.)
1 Technically this exception could be raised arbitrarily, perhaps justified in an Extension Method. However, raising this exception wantonly is not common or good practice or found in the .NET framework and is thus generally a dismissible cause when debugging.