This is the bane of my programming existence. After deploying an application, when this error crops up, no amount of debug dump tells you WHAT object was not instantiated. I have the call stack, that’s great, it tells me roughly where the object is, but is there any way to get .NET to tell me the actual name of the object?
If you catch them while debugging, of course the program breaks right on the offending creature, but if it happens after the program is in the wild, good luck.
There has to be a way.
I’ve explored the exceptions returned in these instances and there is just nothing helpful.
No, it’s not possible. The exception happens because a reference is null, and references doesn’t have names. Variables and class/struct members have names, but it’s not certain that the reference is stored in either of those. The reference could for example be created like this:
If the
GetInstancemethod returns null, there is a null reference exception when you try to use the reference to callDoSomething. The reference is just a return value from the method, it’s not stored in a variable, so there is nothing to get a name from.If you have debugging information in the compiled assembly, you will get the line number in the stack trace in the exception, but that is as close as you can get.