3

"Object reference not set to a reference of an object" is the single least helpful exception ever.

Also, I still hate Visual Studio. Sorry.

Comments
  • 0
    Not really, you just know that you try to use null as variable. As simple as that.

    You should just read it as "Object reference which you are trying to use is not set to any known object and right now it is probably a null"
  • 0
    @MaLiN2223 when you're using a "variable" from an array that's converted from an HTTP response from an internal API server you have no control of - no, not really.
  • 0
    @contrastful but it still can be null, can it not ?
  • 0
    @MaLiN2223 yes, but that information is useless, since you don't know why it's null. you'd expect at least a "error parsing http value to variable" exception or something, that would be nice.
  • 0
    @contrastful yes, but that just means they you don't have any null checking before you use it. If there is a chance of null, you need to handle it to make sure you don't try to access properties without checking
  • 0
    @iam13islucky you don't need to explain that to me, I'm not coding for a day, haha. this was mostly a joke, but to be fair, C# exceptions are usually pretty clueless, still.
  • 0
    @contrastful well, I strongly disagree! They are very very informative as long as people provide strings inside them ! But in case empty error message there are somehow miss leading sometime.
  • 3
    The problem with object reference is that they almost never contain info on which reference is not set.

    And especially on multiline object initializers it can be hard to track down.

    I really long for not nullables in C# where the exception will trigger on assign :D. It might come in v7 that id in the works right now.

    Along with pattern matching an immutables I see several whole categories of errors just never happen.
  • 1
    As a newbie grad dev i got this error and asked what it meant. I got the reply "exactly what it says". I agree, not helpful
Add Comment