Finding Null Refernce error

  • Thread starter Thread starter David
  • Start date Start date
D

David

Can someone please advise me how I can track down where the error that
causes the following error message to appear is located in my code


An unhandled exception of type 'System.NullReferenceException' occurred in
system.windows.forms.dll

Additional information: Object reference not set to an instance of an
object.

The error occurs when I am testing port settings by selecting a valid serial
port then invalid port then valid port again.
The code handling this port selection writes to a log each time the port is
attempted to be opened. I suspect that the StreamWriter CLOSE method takes
time and the routine is being called again before the file is physically
closed on the disk.

Could this be an issue ? If so, w\how would I test the file is closed before
the code continues
Whether this is the actual issue in this instance, is there a way I can find
out which object is being refrred to in the error dialog ?

Thanks in advance
 
Wrap your code in a Try Catch block and then print out the stack trace.
It will tell you which line the exception is occurring on.

Try
'Code here
Catch ex as NullReferenceException
MsgBox(ex.StackTrace)
End Try
 

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

Back
Top