I am calling a third-party unmanaged DLL from vb.net (framework 4.5) and on rare occasions the third party DLL thows an AccessViolationExcpetion ("Attempted to read or write protected memory. This is often an indication that other memory is corrupt.").
I have added the <HandleProcessCorruptedStateExceptions> attribute to the method which calls the DLL as follows: -
<Runtime.ExceptionServices.HandleProcessCorruptedStateExceptions> _<SecurityCritical> _
Private Sub CallThirdParty()
Try
UnmanagedFunction(_outputFilename) ' this is the referenced with a DLLImport
Catch ex As Exception
' example code to demonstrate handler
Environment.Exit(0)
End Try
End Sub
When running in debug mode in VS2013 the exception is handled and the application quits as expected. However when I build and run the app outside of VS2013 it just hangs at this point and no exception is handled. The program doesn't even crash.
Is there anything I have missed here which makes debug vs build different?
Thanks for reading this...