Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / February 2004

Tip: Looking for answers? Try searching our database.

NullReferenceException Message Feature Request

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bryan Livingston - 18 Feb 2004 19:21 GMT
I'm guessing that NullReferenceExceptions are by far the most common exceptions thrown in .net.

Why not add the type of the reference to the message?  Have it say something like:
Object reference of type 'string' not set to an instance of an object.

This would really help when trying to figure out where the null reference is happening.

I've just spent the last two days finding a null reference that happens very intermittently.  Having the type would have saved me many hours.

In addition to just the type, you might be able to use reflection to give a property name or variable name.

Bryan Livingston
Alphora.com
Stu Smith - 19 Feb 2004 09:30 GMT
Please tell me you have exceptions set to 'break' in the debugger.... if you
do, it's usually absolutely obvious what the null reference should have
been.

> I'm guessing that NullReferenceExceptions are by far the most common exceptions thrown in .net.
>
[quoted text clipped - 9 lines]
> Bryan Livingston
> Alphora.com
Ben Rush - 19 Feb 2004 21:17 GMT
And if not Bryan, then don't worry - you know to now :-)

> Please tell me you have exceptions set to 'break' in the debugger.... if you
> do, it's usually absolutely obvious what the null reference should have
[quoted text clipped - 18 lines]
> > Bryan Livingston
> > Alphora.com
Stu Smith - 20 Feb 2004 10:17 GMT
Cheeky... they're off by default which seems odd to me.
The options are under Debug -> Exceptions, and I usually have all set to
break (with a few exceptions).
I think the exception already does have the stack trace in it, so even if
you're not running under the debugger you could log the stack trace of an
exception which reaches a certain level.

> And if not Bryan, then don't worry - you know to now :-)
>
[quoted text clipped - 23 lines]
> > > Bryan Livingston
> > > Alphora.com
Bryan Livingston - 21 Feb 2004 19:06 GMT
The exception only happens on a production website and only occours about once every three days.  I havn't been able to reproduce it in a debug environment.

Since we are doing financial transactions on the site I don't exactly have time to dick around with attaching a debugger.  I have to get the site back up right away.

Bryan
   
    ----- Stu Smith wrote: -----
   
    Please tell me you have exceptions set to 'break' in the debugger.... if you
    do, it's usually absolutely obvious what the null reference should have
    been.
   
    "Bryan Livingston" <anonymous@discussions.microsoft.com> wrote in message
    news:6FDA50BD-7BF4-43C6-AD92-6DE18207002C@microsoft.com...
    > I'm guessing that NullReferenceExceptions are by far the most common
    exceptions thrown in .net.
    >> Why not add the type of the reference to the message?  Have it say
    something like:
    > Object reference of type 'string' not set to an instance of an object.
    >> This would really help when trying to figure out where the null reference
    is happening.
    >> I've just spent the last two days finding a null reference that happens
    very intermittently.  Having the type would have saved me many hours.
    >> In addition to just the type, you might be able to use reflection to give
    a property name or variable name.
    >> Bryan Livingston
    > Alphora.com
Bryan Livingston - 21 Feb 2004 19:11 GMT
For the record, here is what one of the program managers for the CLR had to say about it

The NullReferenceException occurs because an instruction like “call [eax+44]” or “mov edx, [esi+24]” has resulted in an access violation.  We don’t retain nearly enough information to form a correspondence between a particular register being NULL at a particular EIP and the fact that a particular reference in the application was null.  Especially since the EIP might be in a shared helper like a write barrier routine or an array helper.  In those cases, we would have to perform a limited stack walk to get the effective EIP

The machinery that would be required to improve this error message is huge.  For the foreseeable future, you will have to rely on debuggers, or on FX code explicitly checking and throwing an appropriate NullArgumentException

Chris.
http://blogs.msdn.com/cbrumme

   
    ----- Bryan Livingston wrote: ----
   
    I'm guessing that NullReferenceExceptions are by far the most common exceptions thrown in .net
   
    Why not add the type of the reference to the message?  Have it say something like
    Object reference of type 'string' not set to an instance of an object
   
    This would really help when trying to figure out where the null reference is happening
   
    I've just spent the last two days finding a null reference that happens very intermittently.  Having the type would have saved me many hours
   
    In addition to just the type, you might be able to use reflection to give a property name or variable name
   
    Bryan Livingsto
    Alphora.com
Kelvin Hoover - 26 Feb 2004 17:01 GMT
Thanks for your suggestion.  I will add this to our list for future
considerations.

Once suggestion is create a trace/log system where you can log activities
on the web site to help debug the problem.

Thanks,
Kelvin

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>Thread-Topic: NullReferenceException Message Feature Request
>thread-index: AcP4rnQ2fwitLh6SR/CMAirGLsHYkQ==
>X-Tomcat-NG: microsoft.public.dotnet.framework.clr
>From: "=?Utf-8?B?QnJ5YW4gTGl2aW5nc3Rvbg==?="
<anonymous@discussions.microsoft.com>
>References:  <6FDA50BD-7BF4-43C6-AD92-6DE18207002C@microsoft.com>
>Subject: RE: NullReferenceException Message Feature Request
[quoted text clipped - 17 lines]
>
>For the record, here is what one of the program managers for the CLR had to say about it:

The NullReferenceException occurs because an instruction like ???call
[eax+44]??? or ???mov edx, [esi+24]??? has resulted in an access violation.
We don???t retain nearly enough information to form a correspondence
between a particular register being NULL at a particular EIP and the fact
that a particular reference in the application was null.  Especially since
the EIP might be in a shared helper like a write barrier routine or an
array helper.  In those cases, we would have to perform a limited stack
walk to get the effective EIP.



The machinery that would be required to improve this error message is huge.
For the foreseeable future, you will have to rely on debuggers, or on FX
code explicitly checking and throwing an appropriate NullArgumentException.

Chris.
http://blogs.msdn.com/cbrumme

   
    ----- Bryan Livingston wrote: -----
   
    I'm guessing that NullReferenceExceptions are by far the most common
exceptions thrown in .net.
   
    Why not add the type of the reference to the message?  Have it say
something like:
    Object reference of type 'string' not set to an instance of an object.
   
    This would really help when trying to figure out where the null
reference is happening.
   
    I've just spent the last two days finding a null reference that
happens very intermittently.  Having the type would have saved me many
hours.
   
    In addition to just the type, you might be able to use reflection to
give a property name or variable name.
   
    Bryan Livingston
    Alphora.com

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.