How to find out which ref-Variable is null, when exception is null reference

R

Rolf Welskes

Hello,
I have the following problem:
Visual Studio 2003 , dotnet 1.1 (can not go to .net 2.0 !)

an application works fine.
At our customers sometimes there are exeptions, NullReferenceExceptions.

So we know: Reference-Variable is null.
But we do not know WHICH variable is null.

Furthermore we cannot debug it, because the problem is on a machine of our
customer normaly 1000 km away.

We have done the following:

the exception func is for example:

void func()
{
.....

}

We have changed this to
void func()
{
try
{

}
catch
{
//here check of all variables in this method
throw ApplicationException(.... here the info which variables are
null .....);
}
}
This has the problem, that there are cases, that we have this
null-reference exception, but ALL variables used in THIS function are NOT
null.

So this must be a null reference anywhere, which not directly throws an
exception.

The only way to find out it is to change the code so we get further
informations and send so our customers an update
with such implemented checking code. We cannot debug it because in our
system the problem does not exist.


Thank you for any help.
Rolf Welskes
 
J

Jeffrey Tan[MSFT]

Hi Rolf,

Since your exception handling code finds all variables in this function are
not null, I assume the NullReferenceException is not directly caused in
this function. It is likely this function calls some other
properties/methods from .Net Framework, and some code deep in certain
property/method throws the NullReferenceException. Since no code in the
..Net Framework caught this exception, it finally unwind to your user code,
which is caught by your exception handler.

In this scenairo, the best way to find out the root cause is getting the
exact stack trace of the NullReferenceException. In the "catch" clause, you
should get an Exception parameter object, so you may examine
Exception.StackTrace property to get the stack trace of the
NullReferenceException.

Additionally, can you tell me the type of your application? Console type or
Winform type? In .Net Winform application, the default exception handler
will pop up a dialog including the stack trace and other useful information
of the exception, so there is no need for you to explicitly print out the
stack trace.

With getting the stack trace, the top of the stack trace will reveal the
deepest method that caused the exception. Then you may further check the
method parameters and variables to see why NullReferenceException is
generated.

Finally, for such type of debugging on production environment, the best way
is downloading the Adplus from Microsoft and obtain a crash mini-dump of
the NullReferenceException. Then you may debug the dump on the development
machine without disturbing the customer. Please refer to the link for the
details of using ADPlus:
"How to use ADPlus to troubleshoot "hangs" and "crashes""
http://support.microsoft.com/kb/286350

If it is possible for you to install the windbg on the customer's machine,
you may refer to the blog entry below to know how to use windbg to
troubleshoot the crash(I wrote this blog for our team 2 month ago):
"How to debug application crash/hang in production environment?"
http://blogs.msdn.com/msdnts/archive/2006/11/24/how-to-debug-application-cra
sh-hang-in-production-environment.aspx

Anyway, please feel free to feedback your progress or concern, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top