unhandled exception not caught by SA
JDHnz
Posts: 16
Today is my first day at trying out using Smart Assembly, so I could potentially be doing something really silly, but if I am then I can't see it.
I have spent the past 30 months migrating our big VB6 application to VB.NET. We had produced our own tool for augmenting the code in the VB6 project with error handling and reporting, so rather than trying to get that working in .NET too, we thought it would be easier and faster to investigate third-party tools to do the job and SA was first on the list.
After some initial false starts I've managed to process the WinForms application assembly and get a new assembly that runs ok and lets me get into testing the results. I have been able to generate an unhandled exception from our app that looks to be the result of a late-bound call which now fails because of obfuscated method names not being what it is expecting.
The problem is that I was expecting this to be handled by the standard template provided by SmartAssembly, but instead I get the regular WinForms unhandled exception dialogue box. I have my SA project set with the "I want errors reported in my application" option selected.
Obviously I am going to have to change the code so that the call is no longer late-bound, but before I worry about that I want to be sure that the error reporting is sending reports back to me of any problems encountered.
What am I missing?
I have spent the past 30 months migrating our big VB6 application to VB.NET. We had produced our own tool for augmenting the code in the VB6 project with error handling and reporting, so rather than trying to get that working in .NET too, we thought it would be easier and faster to investigate third-party tools to do the job and SA was first on the list.
After some initial false starts I've managed to process the WinForms application assembly and get a new assembly that runs ok and lets me get into testing the results. I have been able to generate an unhandled exception from our app that looks to be the result of a late-bound call which now fails because of obfuscated method names not being what it is expecting.
System.MissingMemberException: Public member 'RemoveField' on type '#vH' not found. at Microsoft.VisualBasic.CompilerServices.Symbols.Container.GetMembers(String& MemberName, Boolean ReportErrors) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.CallMethod(Container BaseReference, String MethodName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, BindingFlags InvocationFlags, Boolean ReportErrors, ResolutionFailure& Failure) at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn) at #Fq.#Qqb.#Tob() at #Fq.#Qqb.#I3(Object eventSender, FormClosedEventArgs eventArgs) at System.Windows.Forms.FormClosedEventHandler.Invoke(Object sender, FormClosedEventArgs e) at System.Windows.Forms.Form.OnFormClosed(FormClosedEventArgs e) at System.Windows.Forms.Form.WmClose(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
The problem is that I was expecting this to be handled by the standard template provided by SmartAssembly, but instead I get the regular WinForms unhandled exception dialogue box. I have my SA project set with the "I want errors reported in my application" option selected.
Obviously I am going to have to change the code so that the call is no longer late-bound, but before I worry about that I want to be sure that the error reporting is sending reports back to me of any problems encountered.
What am I missing?
Comments
Here are some ideas:
It could be a clash between your error handling code and the error handling code inserted by SmartAssembly. Is your code still implementing an unhandled exception handler ?
Or it could be related to multiple app domains. Are you using multiple app domains?
Can you throw some simple exceptions elsewhere in your code ? Are any of these reported correctly ?
Is it possible you are using a build script which uses an older saproj that does not have error reporting turned on.
James Davies
Technical Support Engineer
Red Gate Software
Not intentionally. Is there anything in the .NET framework classes used to support code migrated from VB6 that could be doing so behind the scenes? I just added one right at the beginning of the Main() method and it was handled correctly. I will try adding more around the area where it is not reporting them correctly to see if that provides any more clues as to what is going awry. No, we're not using a build script yet. I'm still using the tools interactively at this stage.
Our app runs something like this: My experiments showed that any exceptions thrown before the call to System.Windows.Forms.Application.Run(fMDI) would be caught by the SA UnhandledException handler, but after that they would be dealt with by the default Winforms handler.
You will notice that a click on the Throw Exception button on the "Splash" form, the first time it is opened, results in the standard SmartAssembly error window popping up, but a click on the Throw Exception menu item in the MDI or a click on the Throw Exception button on the Splash window after logging in and back out again, results in the default Windows Forms exception window.
It seems that extra calls to Application.Run() cause a problem with this.
It could be that calls to Application.Run() start a new message loop and SA is hooked into the old one causing the exceptions to not be reported.
Thanks for the reproduction of the problem. I will add this to our bug tracking system and see what the developers say.
James Davies
Technical Support Engineer
Red Gate Software
James Davies
Technical Support Engineer
Red Gate Software
This problem is because the current thread context (which is where the unhandled exception handler gets attached) is completely removed at the end of the Application.Run method.
Please use Form.Show instead of Application.Run - http://social.msdn.microsoft.com/Forums/en-us/winforms/thread/aead5e9a-2e06-4adf-aecc-f45a2a633768
James Davies
Technical Support Engineer
Red Gate Software