Can't catch native exception in managed code
.net, c#, exception
Solution
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.
Problem
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: - Try/catch block - `AppDomain.UnHandledExption += ...` - Marking the `RuntimeCompatibilityAttribute(WrapNonExceptionThrows = true)` in the AssmblyInfo file. What else can I do?