Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

getting NullReferenceException information

Posted on 2004-08-05
3
Medium Priority
?
315 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 200 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 200 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 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

876 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