How to intentionally crash an application with an AccessViolationException in c#?
I have a console application that use an unmanaged DLL that eventually crashes because of access violation exceptions. Because of that, I need to intentionally throw an AccessViolationException
to test how it behaves under certain circumstances.
Besides that, it must be specifically an AccessViolationException
because this exception is not handled by the catch blocks.
Surprisingly, this does not work:
public static void Crash()
{
throw new AccessViolationException();
}
Neither this:
public static unsafe void Crash()
{
for (int i = 1; true; i++)
{
var ptr = (int*)i;
int value = *ptr;
}
}