Solved

getting NullReferenceException information

Posted on 2004-08-05
3
288 Views
Last Modified: 2010-04-15
Hi,
When i get a NullReferenceException or "Object reference not set to an instance of an object." exception, how do i find out what object reference was not instantiated?

Thanks
0
Comment
Question by:3Mann
3 Comments
 
LVL 2

Accepted Solution

by:
AnnamalaiSwamy earned 50 total points
ID: 11733800
Catch the NullReferenceException by try...catch block and get more information about uninstantiated object through "Source" property of NullReferenceException object.


e.g.,

try
{
  some error
}catch(NullReferenceException e)
{
    msg = e.source;   //gives more details
}
Thanks
0
 
LVL 20

Assisted Solution

by:TheAvenger
TheAvenger earned 50 total points
ID: 11733801
You should have a look at the StackTrace of the exception and thus find the line where the exception occured. Then debug the application by putting a break point on that line and when the application reaches the point, you can see the values of all variables used there - see which is null.
0
 
LVL 2

Assisted Solution

by:Daeljan
Daeljan earned 50 total points
ID: 11736666
Also dont forget to unroll inner exceptions to get as much info as possible:

assuming 'e' is the System.Exception

// examine:       e.Message, e.StackTrace

System.Exception innerE = e.InnerException;
while (innerE != null)
{
    // examine:       e.Message, e.StackTrace
    innerE = innerE.InnerException;
}
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question