Red Gate forums :: View topic - unhandled exception not caught by SA
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SmartAssembly 6
SmartAssembly 6 forum

unhandled exception not caught by SA

Search in SmartAssembly 6 forum
Post new topic   Reply to topic
Jump to:  
Author Message
JDHnz



Joined: 01 Sep 2008
Posts: 13

PostPosted: Tue Jan 17, 2012 2:47 am    Post subject: unhandled exception not caught by SA Reply with quote

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.

Code:
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?
Back to top
View user's profile Send private message
james.davies



Joined: 19 Apr 2011
Posts: 46

PostPosted: Wed Jan 18, 2012 4:48 pm    Post subject: Reply with quote

Hi,

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.
_________________
Thanks,
James Davies
Technical Support Engineer
Red Gate Software
Back to top
View user's profile Send private message
JDHnz



Joined: 01 Sep 2008
Posts: 13

PostPosted: Wed Jan 18, 2012 10:15 pm    Post subject: Re: Reply with quote

james.davies wrote:
Hi,

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 ?

We did have a very basic one in the earlier stages of the migration, as a placeholder for when we were still considering doing our own error reporting system, but this has all been removed from the project now.

Quote:
Or it could be related to multiple app domains. Are you using multiple app domains?

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?
Quote:
Can you throw some simple exceptions elsewhere in your code ? Are any of these reported correctly ?

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.
Quote:
Is it possible you are using a build script which uses an older saproj that does not have error reporting turned on.

No, we're not using a build script yet. I'm still using the tools interactively at this stage.
Back to top
View user's profile Send private message
JDHnz



Joined: 01 Sep 2008
Posts: 13

PostPosted: Thu Jan 19, 2012 2:28 am    Post subject: Re: Reply with quote

james.davies wrote:
Or it could be related to multiple app domains. Are you using multiple app domains?

While I'm fairly certain that we're not using multiple app domains, we might be doing something a little different with the message loop from the standard Winforms app, by having multiple calls to System.Windows.Forms.Application.Run() for when we have different forms as the main window of the app at different stages.

Our app runs something like this:
Code:

Sub Main
    fSplash = New frmSplash
    fSplash.Show()

    ' program initialisation code goes here (open DB connection, etc.)

    System.Windows.Forms.Application.Run(fSplash)

    Do While fSplash.IsLoggedIn
        fSplash = Nothing

        fMDI = New frmMDI
        System.Windows.Forms.Application.Run(fMDI)

        If fMDI.IsExitingApp Then Exit Do
        fMDI = Nothing

        fSplash = New frmSplash
        fSplash.Show()
        System.Windows.Forms.Application.Run(fSplash)
    Loop
End Sub

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.
Back to top
View user's profile Send private message
JDHnz



Joined: 01 Sep 2008
Posts: 13

PostPosted: Tue Jan 24, 2012 12:18 am    Post subject: Reply with quote

I have created a minimal project that reproduces the problem I have encountered. It can be downloaded from here.

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.
Back to top
View user's profile Send private message
james.davies



Joined: 19 Apr 2011
Posts: 46

PostPosted: Wed Jan 25, 2012 5:44 pm    Post subject: Reply with quote

Error reporting uses the standard application message loop.

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.
_________________
Thanks,
James Davies
Technical Support Engineer
Red Gate Software
Back to top
View user's profile Send private message
JDHnz



Joined: 01 Sep 2008
Posts: 13

PostPosted: Tue Feb 07, 2012 9:27 pm    Post subject: Reply with quote

Has any progress been made on getting SA to cope with this scenario?
Back to top
View user's profile Send private message
JDHnz



Joined: 01 Sep 2008
Posts: 13

PostPosted: Mon Feb 20, 2012 11:09 am    Post subject: Reply with quote

[bump] Anything?
Back to top
View user's profile Send private message
james.davies



Joined: 19 Apr 2011
Posts: 46

PostPosted: Tue Feb 21, 2012 3:58 pm    Post subject: Reply with quote

There are no comments yet from the developers on this bug. I will try to get them to take a look.
_________________
Thanks,
James Davies
Technical Support Engineer
Red Gate Software
Back to top
View user's profile Send private message
james.davies



Joined: 19 Apr 2011
Posts: 46

PostPosted: Fri Feb 24, 2012 12:22 pm    Post subject: Reply with quote

(Have heard from developer regarding this:)

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
_________________
Thanks,
James Davies
Technical Support Engineer
Red Gate Software
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group