Object reference not set to an instance of an object

G

Guest

I keep getting the error "Object reference not set to an instance of an
object." The unhandled exception is a System.NullReferenceException. It is
occurring in an "unknown module". How do I load within the IDE debug symbols
for system.dll, drawing.dll, forms.dll to trace this error?
 
M

Marcos Stefanakopolus

The error is almost certainly in your code, not in any of those DLLs. I
would bet money that somewhere you have a variable that is declared to be of
some reference type, but you never assigned it to a "new" object of that
type. E.G:

ArrayList foo;
foo.Add("hi there");

This will generate that same error, whereas:

ArrayList foo;
foo = new ArrayList();
foo.Add("hi there");

will work fine. I most often trip myself up this way when I've got a
non-static field in a class that is of some reference type, but I forget to
initialize it in the constructor. That's about the only situation I ever
run into where it even makes sense to separate the declaration of the
variable from the initialization anyway. In your case, if you really think
the exception is originating from within one of those DLLs, then you're
probably passing an uninitialized object into some library routine, and are
triggering the exception that way.
 
G

Guest

Hi Steve,

A NullReferenceException exception is an exception that is thrown when there
is an attempt to dereference a null object reference. This could be caused by
a multitude of items. Can you give the group more information regarding your
error? Perhaps some sample code so we can diagnose better.

Thanks.
---------------------------------
 

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