Object reference not set to an instance of an object

Tuesday 11 October 2005

I got this error message from .NET. It basically means "null pointer":

Exception: Object reference not set to an instance of an object.

The more I look at it, the more I hate it. Why are there so many words? Who are we trying to impress? What's an "instance of an object"? Don't they mean:

Exception: Object reference not set to an instance of a class.

And isn't "instance of a class" a fancy way to say "object"? So shouldn't it be:

Exception: Object reference not set to an object.

And what else would it be set to? Can't we just shorten this to:

Exception: Object reference not set.

Or why don't we just say what we mean:

Exception: Null object reference.

Or, (heaven forbid):

Exception: Null pointer.

I know, I know, they aren't pointers, they're object references. Whatever. Bite me.

Comments

[gravatar]
John Stefanko 4:47 PM on 11 Oct 2005

That error message sounds like it was written by an engineer!

:)

[gravatar]
Pete 5:02 PM on 11 Oct 2005

ROTFL.

[gravatar]
Jay P. 6:04 PM on 11 Oct 2005

Written by an engineer? I don't know. If it *was* written by a fellow engineer, it'd be pretty close to what Ned said:

"Exception: Null pointer. Bite me!"

[gravatar]
christopher baus 7:22 PM on 11 Oct 2005

That's funny. I keep think the same thing. I could live with Null object reference as it uses C# terminology and is to the point.

[gravatar]
Nate Finch 9:27 AM on 12 Oct 2005

I agree with Chris and Ned.... "Null object reference" is perfect. The first time I saw this error, I was like "wha...!?" Then I finally deciphered their crazy wording and came to the same conclusion as everyone else.

You might as well change C++'s null pointer error to "Object pointer not set to address of object" :P

[gravatar]
brian 5:14 PM on 12 Oct 2005

It's not perfect, how about telling us what object wasn't set? All we know is that somewhere, there is a null reference. You might as well say "something's wrong"

[gravatar]
Bob 11:06 AM on 13 Oct 2005

Brian: this is just the message associated with NullReferenceException. As with NullPointerException in Java the code that catches the exception has access to the stack trace.

It's not clear where Ned saw this message but normally there would be a stack trace too. Code that just prints the exception text and doesn't log the stack is dopey as the message text.

[gravatar]
Chris Reckling 10:41 PM on 13 Oct 2005

You are too funny! This one got a "What are you laughing at?" from my wife, as I sit here in front of the TV...

Chris

[gravatar]
Charles Monk 4:31 AM on 14 Oct 2005

In VB6, the same error was "Object variable or With block variable not set". That's not so bad, if you're happy with using "variable" in that way.

The "or With block variable" part is correct, but confusing. Presumably some engineer couldn't resist including that.

[gravatar]
Loz Hygate 4:48 AM on 14 Oct 2005

Is this error specific to marshalling over the managed boundary?

I think it means the thing returned from an unmanaged call couldn't be coerced into the correct managed type. The most obvious reason would be a null pointer in unmanaged space, but maybe there are other possibilities. A misaligned pointer also springs to mind.

Add a comment:

name
email
Ignore this:
not displayed and no spam.
Leave this empty:
www
not searched.
 
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.