"Object reference not set to an instance of an object": why can't .NET show more details?

Posted by Simon Chadwick on Stack Overflow See other posts from Stack Overflow or by Simon Chadwick
Published on 2010-05-27T02:22:43Z Indexed on 2010/05/27 2:31 UTC
Read the original article Hit count: 521

Filed under:
|
|

"Object reference not set to an instance of an object"

This is probably one of the most common run-time errors in .NET. Although the System.Exception has a stack trace, why does the exception not also show the name of the object reference field, or at least its type?

Over the course of a year I spend hours sifting through stack traces (often in code I did not write), hoping there is a line number from a ".pdb" file, then finding the line in the code, and even then it is often not obvious which reference on the line was null. Having the name of the reference field would be very convenient.

If System.ArgumentNullException instances can show the name of the method parameter ("Value cannot be null. Parameter name: value"), then surely System.NullReferenceException instances could include the name of the null field (or its containing collection).

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET