Search code examples
.net-2.0windbgsos

which object is causing NullReferenceException


Dumpfile is reporting a NullReferenceException. I can see the stacktrace as which method is throwing this exception. This method itself is kind of long and doing lot of things, Is there someway I can determine which object is actually been null?


Solution

  • A NullReferenceException indicates the lack of an object - there's no such thing as a null object. I assume you mean which variable was null, or more precisely which expression evaluated to null. No, there's nothing which will indicate that.

    If you're using a debug build, you should get line numbers in the stack trace, which should help you to pin it down to an individual statement. If you're using a release build, you probably don't have line numbers - this is one of many reasons to keep your methods short and sweet.

    Alternatively, if you're using windbg and can make it break when the exception occurs, that should give you a good indication, of course...