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
You cannot cause ExecutionEngineException easily unless you reproduce the issue (even if you have to do that in production environment). Microsoft has utilities such as DebugDiag that can help you capture full memory dumps when such exceptions occur,
http://blogs.msdn.com/b/chaun/archive/2013/09/15/steps-to-trigger-a-user-dump-of-a-process-with-debugdiag-1-2-when-a-specific-net-exception-is-thrown.aspx
and via dump analysis it is easy to locate the culprit. Don't expect your logs can tell, as when this exception occurs the CLR crashes, and your logs never go that deep.