I know Access Violation Exception
is a serious problem that I should not really try to handle.
I also know that in the latest version of .Net, one can handle this exception by
- put this
<legacyCorruptedStateExceptionsPolicy enabled="true">
in the config and all thecatch
block would be able to catch the errors - Decorate the methods you want to catch these exceptions in with the
HandleProcessCorruptedStateExceptions
attribute
Actually this made it very clear.
But my case is a little bit different and I cannot seem to find the solution:
I am using an unmanaged c++ library which I will initialise it at some point of my application. Then this dll itself will perform some tasks by itself(pulling data from server to cache, logging etc.) This Access Violation Exception looks to be thrown during this process, not when the appication directly call the dll's api. So I have no way to try catch
the offending logic.
At this stage I have managed to catch it in AppDomain.CurrentDomain.UnhandledException
like so:
[HandleProcessCorruptedStateExceptions, SecurityCritical]
private static void CurrentDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Logger.Error("Unhandle Exception", (Exception)e.ExceptionObject);
}
But I still cannot quite prevent the application from crashing. I know I probably should just let the application crash. But I really believe this error is not as bad as it appears and I just need to know how to suppress it, even though I might not use it.
Any thoughts?