As a developer, we often encounter that exception: NullReferenceException
with the well known error message:
Object reference not set to an instance of an object
Is it not possible for the .NET framework to return something a little bit more meaningful?
Something such as:
Object of type X named Y not set to an instance of an object
An object doesn't have a name - so how can it tell you the name? The null reference may have been loaded from a variable - or it might have been returned by a method, property etc.
The JIT could probably look at the stack information to work out what the declared reference type was, but I'm not sure how often this would help - and doubtless it would slow things down.
I can't say I've ever found this to be a huge burden when it comes to debugging - if there are lots of things which can be null on a single line, that usually suggests that it's worth splitting them up more.
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