I'm developing under Windows 7 IIS 7.5.7600.16385 with VS2013 and .net 4.5.1.
Using a combination of C#, managed C++ and native C++.
I need to catch memory access violation exceptions thrown by the native C++ code in the C# code. Under .net 2.0 the memory access violation exceptions were caught without problem.
For .net 4.0 the exception behavior for "Corrupted State Exceptions" (like memory access violation) has changed. By default, they are no longer caught by the application code.
<runtime>
<legacyCorruptedStateExceptionsPolicy enabled="true" />
</runtime>
is supposed to restore the pre .net 4.0 behavior.
If I place the legacyCorruptedStateExceptionsPolicy lines above in the web applications web.config it seems to be ignored. A forced memory access violation is not caught and terminates the web server.
I know I am modifying the correct web.config because if I introduce an error in the web.config IIS tells me there is an error and the path is that of my web.config. I've checked my entire system, there are no other .config files that set the element to"false".
If I place the legacyCorruptedStateExceptionsPolicy lines above in the .net 4.0 machine.config it works. The exception will be caught by my code.
If I create a test application and place the legacyCorruptedStateExceptionsPolicy lines above in app.config it will also catch memory access violation exceptions.
Using [HandleProcessCorruptedStateExceptionsAttribute()] also works, but in the short term it is not practical to modify all the calling code.
I must be missing something.
It seems that the legacyCorruptedStateExceptionsPolicy is not supported by web.config?
Does the element belong in a different location than in machine.config or app.config?
Is there some other way of restoring the pre .net 4.0 "Corrupted State Exceptions" behavior?
Thanks.
John