We have a situation where our application sometimes raises an ExecutionEngineException. I thought that when it happens, the application should crash, but it does not crash. And even if the event viewer claims that the application was terminated - it continues running! Only seems that the offending thread is silently killed.
The problem is that we are unable to recreate the conditions when it occurs - the suspected code is executed thousands of times before the exception occurs. There is nothing in the logs. In short - we are puzzled.
I would like to be able to generate this exception at will in order to learn how our application behaves when it happens. Of course, it must be thrown by the framework itself, issuing throw new ExecutionEngineException does not count.
So, my question is - how can I cause it reliably? Please, provide a code sample.
We are on .NET 4, moving soon to .NET 4.5
From the MSDN documentation:
In case the workaround suggested by the MSDN documentation doesn't work for you, you will have to test based on what you know about your software.
Now, creating a test application that simulates load, multi-thread behaviour and memory consumption of your real application is one thing - it is probably better to use the actual software as test software (perhaps augmented with some additional debug-logging + test code). That means, unfortunately no code sample here :(
To make the load tests meaningful, you would also need to run these tests on a test system that has a very similar, if not identical hardware/software configuration as your production system. And only then you will be able to find out if your ExecutionEngineException is caused by the GC or by an otherwise corrupted runtime.