Solved

getting NullReferenceException information

Posted on 2004-08-05
3
285 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now