Red Gate forums :: View topic - Error Reporting Not Working With AccessViolationException
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

Error Reporting Not Working With AccessViolationException

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



Joined: 13 Sep 2011
Posts: 14
Location: London, UK

PostPosted: Tue Sep 13, 2011 1:22 pm    Post subject: Error Reporting Not Working With AccessViolationException Reply with quote

Hi,

As a proof-of-concept, I have created a sandbox WinForms application, that when a button is pressed, the event handler code is thus:

Code:

Marshal.StructureToPtr(new Point(), new IntPtr(-1), false);


This is to force an AccessViolationException to see whether the exception report would show the memory address and instruction address from the exception.

After SmartAssembly processes the application instead of a SmartAssembly dialog, the application immediately terminates (or shows the default Windows error reporting dialog).

I've also tried explicitly catching the AccessViolationException and using
the ExceptionReporting.Report(Exception) method to report it manually, to no avail.

It only seems to report the exception if I throw the AccessViolationException manually (which doesn't let me see the private fields containing the memory address and the instruction address), but that's obviously no good in practice.

Is there a reason why this isn't working? I want to be able to generate exception reports for AccessViolationExceptions so that if a crash occurs in a native component called via Inteop we can diagnose the issue in the native code to some degree via the managed exception reports.

Even without the detailed information about the AccessViolationException, even the fact that one happens appears to be completely missed by the SmartAssembly error handling.

Regards,
Martin
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6645

PostPosted: Tue Sep 13, 2011 2:13 pm    Post subject: Reply with quote

As far as I know, AccessViolation exceptions are so critical they termainate the runtime. You can't really trash memory and expect the runtime to continue on to process the exception.

You may want to have a look at this thread here as there may be an app config setting you can try: http://stackoverflow.com/questions/3312003/is-it-possible-to-catch-an-access-violation-exception-in-net
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6645

PostPosted: Tue Sep 13, 2011 3:51 pm    Post subject: Reply with quote

From MSDN regarding the UnhandledExceptionHandler (SA uses this):
Quote:
Starting with the .NET Framework version 4, this event is not raised for exceptions that corrupt the state of the process, such as stack overflows or access violations, unless the event handler is security-critical and has the HandleProcessCorruptedStateExceptionsAttribute attribute.
Back to top
View user's profile Send private message
martincostello



Joined: 13 Sep 2011
Posts: 14
Location: London, UK

PostPosted: Tue Sep 13, 2011 4:45 pm    Post subject: Reply with quote

Thanks Brian. I wasn't aware of the change made in .NET 4.0 for the handling of AccessViolationException. I should have maybe done a bit more digging around on MSDN first. I compiled my sandbox app to test this out in VS2010, so it defaulted to .NET 4.0.

Either changing the .NET Framework version, adding the configuration setting it behave as expected.

With .NET 4.0 and without a process-wide change however, the only way I can get SmartAssembly to catch the AccessViolationException is to add the [HandleProcessCorruptedStateExceptions] attribute and then re-throw the exception.

Maybe SmartAssembly could be changed at some point to allow an option for .NET 4.0 assemblies with error reporting added to get the code injected into the assembly to decorate your error handler with the appropriate attribute to allow it to catch such problems if wanted in the .saproj file?

We would certainly find this beneficial as we could report exceptions caused by our native components, and then prevent the user from continuing, giving us enough leeway to report the error, but not allowing the process to continue longer than neccessary with potentially corrupted memory.

Thanks,
Martin
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6645

PostPosted: Tue Sep 13, 2011 4:58 pm    Post subject: Reply with quote

Hi Martin,

I have created an issue with development ( SA-1096 ) to see if they can add the attributes to SmartAssembly's UnhandledExceptionHandler so that it will report access violations.

Thanks for your feedback!
Back to top
View user's profile Send private message
martincostello



Joined: 13 Sep 2011
Posts: 14
Location: London, UK

PostPosted: Tue Sep 13, 2011 4:59 pm    Post subject: Reply with quote

Thanks Brian.

Martin
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