.net application crashes with weird exceptions

C

Christian Kreimer

Hi

I created an C# windows forms application that holds a user control. The
user control itself is an editor for geographical information systems and is
based on an ActiveX Library for providing basic geografic operations. It
works fine most of the time, but sometimes it crashes with weird messages
and i'm not able to track the error down - to find out the reason for this
problem. It's some kind of an memory problem - I get the message that the
programm points to an illegal memory area (where it cannot write), and then
the application exits with the stack trace below.
Another problem is that i cannot reconstruct the message - that means
sometimes it occures very often, sometimes (with the same operations
executed) it runs stable for several minutes.


Message: Object reference not set to an instance of an object.
stack trace: at
System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc,
IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.AxHost.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc,
IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmSysCommand(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc,
IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Form.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmNcButtonDown(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMetho
ds+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason,
Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Jrs.Geo.Mogis.HostApplication.HostApp.Main() in
c:\sourcesafe\mogishostapp\classes\hostapp.cs:line 1433
The program '[3080] MogisHostApp.exe' has exited with code 0 (0x0).



Has anyone an idea - what I should do to prevent this error.

Thanks, for your time
Chris
 
M

Morten Wennevik

"Object reference not set to an instance of an object"

....is caused by prematurely calling of the object (before it is created)
or calling of an object that has been terminated elsewhere and no longer
exists (for instance threads that are running while the parent is closed,
and then tries to notify it's parent later on)

I can't really tell from the code, but it may be that the control is
terminated and then you try to access it again.
Or something in the control is terminated and then reaccessed.
 
C

Christian Kreimer

Well - you are rigth but the problem is that this error occures very
casually and is not really reconstructable. And the objects that are listed
in the stack trace are all from the .NET framework and not from my code, so
I don't know how I can find out wants going wrong.

"Object reference not set to an instance of an object"

....is caused by prematurely calling of the object (before it is created)
or calling of an object that has been terminated elsewhere and no longer
exists (for instance threads that are running while the parent is closed,
and then tries to notify it's parent later on)

I can't really tell from the code, but it may be that the control is
terminated and then you try to access it again.
Or something in the control is terminated and then reaccessed.
 

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