简体   繁体   中英

How to cause .NET 4 to throw ExecutionEngineException?

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 some cases, an application that targets the .NET Framework may throw an ExecutionEngineException exception during garbage collection when an application or the system on which it is running is under a heavy load. In this case, To work around this issue, you can disable concurrent garbage collection by modifying the application's configuration file. For more information, see How to: Disable Concurrent Garbage Collection .

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM