views:

363

answers:

2

We received some hard to reproduce error reports. The users gets the "An error occurred. The application will now exit." message box and then the app exits.

In Main() I write the exception to a log file:

System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
at System.Drawing.Image.FromHbitmap(IntPtr hbitmap, IntPtr hpalette)
at System.Drawing.Image.FromHbitmap(IntPtr hbitmap)
at System.Drawing.Icon.ToBitmap()
at System.Windows.Forms.ThreadExceptionDialog..ctor(Exception t)
at System.Windows.Forms.Application.ThreadContext.OnThreadException(Exception t)
at System.Windows.Forms.Control.WndProcException(Exception e)
at System.Windows.Forms.Control.ControlNativeWindow.OnThreadException(Exception e)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Wfm.AppMain.Main()

What confuses me is that the ThreadExceptionDialog is in the stack trace. I suppose that is the dialog that shows the "An error occurred. The application will now exit." message.

Is this an unrelated error or is the dialog rethrowing the exception? How can I get the original exception?

A: 

You need a dump file, then use SOS to get all the exception objects that are on the stack.
BTW what the resource situation on that machine? it looks like the application could not convert a icon into bitmap which can happen under extreme resource pressure.

You can create a dump by using ADPlus in hang mode once you see the exception window.

Shay Erlichmen
How do I get the app to generate a dump file? It isn't crashing.
chris
You can create a dump by using ADPlus in hang mode once you see the exception window.
Shay Erlichmen
A: 

It looks like the OnThreadException method has been invoked, which means that you should be able to set up an event handler for the Application.ThreadException event, in order to examine the exception more in detail.

Fredrik Mörk
I will look into that, thanks!
chris