Solved

getting NullReferenceException information

Posted on 2004-08-05
3
299 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

734 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