Solved

getting NullReferenceException information

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
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: …

628 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