"Object reference not set to an instance of an object": why can't .NET show more details?
- by Simon Chadwick
"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).