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.
To fix "Object reference not set to an instance of an object," you should try running Microsoft Visual Studio as an administrator. You can also try resetting the user data associated with your account or updating Microsoft Visual Studio to the latest version.
The error means that your code is trying to access/reference an object that is a null valued object that is not there in memory.
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:
someObject.GetInstance().DoSomething();
If the GetInstance
method returns null, there is a null reference exception when you try to use the reference to call DoSomething
. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With