Came across this recently: “ExecutionEngineException occurs during Garbage Collection“ and the subsequent KB article on support.microsoft.com. Last year I was finding some random crashes in a couple of .Net 4.0 Windows Service Applications, and this might have been part of the problem.
Right, so what does this mean? Basically there’s some heap corruption occurring when the .Net 4.0’s runtime attempts to perform garbage collection. It (to me) looks like a bit of a race condition between foreground and background concurrent GC actions.
From the KB article:
This bug can be encountered when the Garbage Collector is freeing and compacting memory. The error can happen when the Concurrent Garbage Collection is enabled and a certain combination of foreground Garbage Collection and background Garbage Collection occurs. When this situation happens you will see the same call stack over and over. On the heap you will see one free object and before it ends you will see another free object corrupting the heap.
..and the (current) resolution is to disable concurrent garbage collection. To do so there’s a configuration you can set which is described here.
Want to know the real kick in the pants?
By default, the runtime runs garbage collection concurrently
Let’s just hope there’s a hotfix for this one soon..