Finding the cause of System.AccessViolationException

What you are experiencing is the exact equivalent to “The program has experienced a problem and will now close”, except it’s being caught by the .NET runtime, rather than the OS.

Looking at the stack trace, it’s not being triggered by your code, which makes me think that it’s coming from a worker thread spawned by a library you’re using or a custom control.

The only way to track something like this would be to run the native libraries under a debugger, which should trap the access violation before it bubbles up to the CLR layer. This can be easy or hard.

If the native code is your own project, then the easiest way to set this up is to put both the .NET project and the C++ project in the same solution, and ensure that the .NET project is referencing the C++ project. If you post more details about your environment, I may be able to give more specific advice.

Leave a Comment