I have a mixed .NET and native code console application. The application process is terminated due to Visual C RunTime Library fatal error. Even though I am using the following, the managed code doesn’t catch the native exception:
AppDomain.UnHandledExption += ...
RuntimeCompatibilityAttribute(WrapNonExceptionThrows = true)
in the AssmblyInfo file.What else can I do?
Native exceptions have changed in .NET 4 so that they can not be catched with a standard catch block. You specifically have to mark the function where the exception is being thrown as [HandleProcessCorruptedStateExceptions]
to be able to catch it.
More here, http://msdn.microsoft.com/en-us/magazine/dd419661.aspx
Watch out for the notes in that article, like if you'd like to catch them normally rather than follow their advice of executing the finally block and exiting, add legacyCorruptedStateExceptionsPolicy=true
into your config file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With