A_Kumar

I have attached Application.ThreadException in my .net windows application to a method and logging the exception in log. Below is logged before application crash

Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: System.Windows.Forms
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.WmUpdateUIState(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.ParkingWindow.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Above case happens at random times without a specific pattern of events. This is a huge application and above log doesn't give me enough information for the cause of crash..

can anyone pls suggest some way of finding the root cause of the error.

Regards

AK



Re: .NET Base Class Library .Net windows application crashes at random times

nobugz

You've got unmanaged code (CallWindowProc) generating a managed exception. That's mighty strange of course, maybe the marshaler is bombing. My best guess is that internal CLR state is corrupted. Debugging this will be awfully hard, start by taking a good look at any unmanaged code you may have in your project.





Re: .NET Base Class Library .Net windows application crashes at random times

Carsten Kanstrup

This is pure guesswork, but very urgent messages like mouse cursor movements (WM_SETCURSOR) and change of active window (WM_ACTIVATE and WM_SETFOCUS) are handled immediately bypassing the message queue.

System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) could be such a call I don't think that it is you, who make an unmanaged call - it is probably internal in .NET. The error message probably tells you (guesswork again) that it cannot build the message - probably because hWnd is not defined. My guess is that a WM_ACTIVATE or WM_SETFOCUS message or something like that is send to a window, which has not yet been opened (hWnd does not exist).

This is enough "probably" and "maybe" for now. If it sounds foolish, just forget my input.

EDIT

It is also a possibility that CallWindowProc is called from DispatchMessage(msg) in the message pump (any message - not just the urgent ones), but in that case, the window, which shall receive the message (hWnd), is closed after the message is posted or else the error message would occur at the time the message was posted (no hWnd) and posting is probably not done by means of a CallWindowProc call.

In both situations, I presume that the error message is coursed by a missing window (window handle).





Re: .NET Base Class Library .Net windows application crashes at random times

Feng Chen - MSFT

Hi A_Kumar,

To troubleshoot this issue, we really need the source code to reproduce the problem, so that we can investigate the issue in house. It is not necessary that you send out the complete source of your project. We just need a simplest sample to reproduce the problem. You can remove any confidential information or business logic from it.

Thanks!






Re: .NET Base Class Library .Net windows application crashes at random times

Carsten Kanstrup

Feng Chen

Don't you mean A_Kumar It is not me, who has the problem.





Re: .NET Base Class Library .Net windows application crashes at random times

Feng Chen - MSFT

Hi Carsten,

Yes, I mean, sorry for the type error.

Thanks!






Re: .NET Base Class Library .Net windows application crashes at random times

nobugz

There is no source code involved. This is all pure .NET framework code, doing default processing on the WM_UPDATEUISTATE message. The only logical explanation is damage to the internal CLR state. This is going to be *very* hard to debug. The best the OP can hope for is some other crash that leaves better breadcrumbs.





Re: .NET Base Class Library .Net windows application crashes at random times

A_Kumar

Hello nobugz

thanks for your suggestions.. Interestingly this issue doesn't happens in test environment even during capacity/volume tests. But users are getting irritated with sudden crash of application.

as mentioned earlier, this is a big application and there are too many threads working in the application that even guessing a faulty thread is a big headache.. there are more than one unmanaged components getting accessed. unfortunately I can't share the application code unless I know the code section causing issues.

below entry in the event viewer might help to understand the issue more:

Event Type: Information
Event Source: Application Popup
Event Category: None
Event ID: 26
Date: 2007/09/25
Time: 13:42:59
User: N/A
Computer: COMPNAME
Description:
Application popup: MyApp.exe - Common Language Runtime Debugging Services : Application has generated an exception that could not be handled.

Process id=0x11e8 (4584), Thread id=0x11ec (4588).
Click OK to terminate the application.
Click CANCEL to debug the application.
For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

thanks

AKumar





Re: .NET Base Class Library .Net windows application crashes at random times

A_Kumar

Hello All

During one of the crashes, error logged is different for our application

Exception: System.NullReferenceException
Message: Object reference not set to an instance of an object.
Source: System.Windows.Forms
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+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)

can anyone suggest what this error stands for and how its diff from one above

thanks

Akumar





Re: .NET Base Class Library .Net windows application crashes at random times

nobugz

Using .NET 1.1 Check this KB article.





Re: .NET Base Class Library .Net windows application crashes at random times

A_Kumar

Hello Nobugz

this looks relevent to the errors we are getting (except we use windows XP). But in my case this null reference exception is occuring in a try catch block and I am just logging this error. Still my application crashes after logging this error. Not sure if its due to System.Nullreference exception or the original thread exception that I am trying to handle.

fortunately we are releasing .Net 2.0 build of our application in 2 weeks, so am expecting some better behaviour in new version.

thanks a lot for your help..

Thanks again

AKumar