问题
I'm developing a small C# winforms application that consumes an unmanaged C++ library. I have no access to the code of this library.
If I'm in Visual Studio and I runt my application, do my calls to the library everything is working find. Once I run CTRL + F5 I get an AccessViolationException. I did some testing, created another winforms application in .NET 2.0 (others were in .NET 4.0) and there I don't receive the AccessViolationException. So I thought i'd create a .net 2.0 class library in my .net 4.0 solution and consume that class lib. This didn't help, still I had the AccessViolationException.
Tried setting allow unsafe code, optimize code on and off but that didn't help. Why am I getting the AccessViolationException once I'm out of debug mode?
Thanks
回答1:
I just stumbled upon the same issue. To reproduce the problem in the debugger, I had to go to:
Tools\Options Debugging\General
and disable: Suppress JIT optimization on module load (managed only).
Of course the problem would only appear for a optimized code.
来源:https://stackoverflow.com/questions/2679248/accessviolationexception-outside-visual-studio