Скорее всего дело в нативной библиотеке. Потестил:
#include <exception>
extern "C" {
__declspec(dllexport) void CrashTest()
{
std::exception* ex = 0;
ex->what();
}
}
class Program
{
[DllImport("PInvokeCrashTest.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void CrashTest();
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += (s, e) =>
{
Console.WriteLine(string.Format("EXCEPTION: {0}", e.ExceptionObject.ToString()));
Process.GetCurrentProcess().Kill();
};
CrashTest();
}
}
Получаю
Unhandled Exception: System.AccessViolationException: Attempted to read or write
protected memory. This is often an indication that other memory is corrupt.
at ExceptionTest.Program.CrashTest()
at ExceptionTest.Program.Main(String[] args) in d:\PInvokeCrashTest\Exception
Test\Program.cs:line 25
и application has stopped working окно.
Если добавить в конфиг файл
<runtime>
<legacyCorruptedStateExceptionsPolicy enabled="true" />
</runtime>
то приложение завершается нормально:
EXCEPTION: System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt.
at ExceptionTest.Program.CrashTest()
at ExceptionTest.Program.Main(String[] args) in d:\PInvokeCrashTest\Exception
Test\Program.cs:line 24
Решение взято
отсюда