views:

3499

answers:

11

I've been trying to find out more about this problem and I'm not having much luck. I keep reading that applications should not have this error come up and although that's all fine and dandy, it doesn't tell me what can cause this error to show up.

I know this question is very broad as I'm sure there can be multiple causes for this error so I'll try to narrow it down a bit.

I'm working in VS2003 developing an application that uses C++.NET

The application uses mostly unmanaged code and little managed code (due to heavy interference by the garbage collector). So I'd rate it 95% unmanaged, 5% managed

I've read somewhere that unstable/buggy/incorrect unmanaged code can mess up parts of the CLR memory rendering it corrupt and throwing this error.

Since 95% of the application is unmanaged, I'm not sure where to start looking. Maybe the few classes that interact between managed and unmanaged? What about marshalling data from managed to unmanaged? Can a bad null pointer cause this failure? What other problems can cause this? Array Index out of bounds? What about a Null Object?

Any information/paper/article that can give a nice list of possible causes for the System.ExecutionEngine failure would be appreciated!

Thank you kindly, Alex.

A: 

Honestly, the only time I've ever seen this exception is when I was using the Compuware DevPartner tools to do some profiling and code analysis. DevPartner hooks deep into the core of the CLR to do it's work, but it's full of bugs, so screws the CLR up. I had to reboot my machine (and remember to never click the DevPartner toolbar buttons ever again) to get things to go back to normal.

If you're not using devpartner, then you most likely have some unmanaged code which is trashing some memory used by the CLR. I'd advise first doing a reboot, and then trying to track down whichever bug you have which is trashing the memory. Look for buffer overruns, writing to uninitialised pointers, and all the other usual suspects.

Orion Edwards
Thank you, I wonder if there is a decent unmanaged/managed c++.NET monitoring software that you know about to help me?The application is heavily multi-threaded and asynchronous in 3 different ways. When it runs, it holds a little over 1000 threads so the task of tracking a run-time error is immense...Thank you for your answer, I appreciate the time you took and I will continue to look into this issue. I hope more people can join and give more advice!Alex.
A: 

I got one of these when my C# module (invoked by a C++/MFC app built with /CLR) inadvertently de-referenced a null pointer. So it is possible for the exception to occur due to a bug in the "user code".

Kevin

Kevin
A: 

I'm not 100% sure, but I think I did this once in C# by creating a property that, instead of returning the corresponding private member, it had a typo that returned the actual public property itself.

Greg Askew
That would usually cause a `StackOverflowException`
Kieren Johnstone
A: 

Just to add to the list of possible causes, I've had this error when trying to serialise IEnumerable<> containing a complex type.

Changing from IEnumerable<> to List<> resolved the problem.

Finch
Similar problem here - A service call which returns an IList<> would throw the error because it was returning an instance of Array instead of an instance of List<>
Veli
+1  A: 

There is a known bug when a WCF service tries to return an IList or IEnumerable.

http://connect.microsoft.com/wcf/feedback/details/433569/wcf-throws-an-executionengineexception-when-returning-an-array-as-ilist-t

Jimtronic
+1 - yes - I've hit this one!
Rob Levine
+1  A: 

Had the same problem - my bug turned out to be an argument mismatch between my C# code and my C++ native dll. I had added an argument to the C++ function and failed to add it to the C# side.

Ann
A: 

Although this thread is by now fairly old, I'll mention my own incident with this exception. I've come across it while developing a ArcGIS extension, written with VB.NET (Visual Studio 2005). ArcGIS relies heavily on the COM technology, therefore .NET-COM interop is involved. I haven't found the cause of the exception until now, but I suppose it might have to do with a building-up of un-released COM object instances, since the exception only ever occurs after the software has been crunching geometries and numbers for some time.

stakx
A: 

I had this exception when running unmanaged code in a different version, than I compiled it with.

Maybe that helps someone...

toba303
A: 

I recently discovered that using the std instruction in assembler to set the direction flag without clearing it when you're done (cld) can cause this error. I'm using .Net 4.0.

Brent
A: 

I had this happen and it was because I was calling ::FreeLibrary() multiple times with the same DLL HANDLE. (The DLL was a managed C++ dll: a managed C++ wrapper over some C# functionality)

Adam Tegen
A: 

I've just come across this exception while writing a c# programme using the Unity Framework.

I'm using VS 2010, and .NET 3.5

Basically if you register a type in a UnityContainer:

container.RegisterType<IAClass, AClass>();

but AClass doesn't have a constructor that takes no arguments

class AClass : IAClass
{
   private int a;
   public in A { get { return a; } }
   public AClass(int a)
   {
       this.a = a;
   }
}

then when you come to instantiate the class you'll get the System.ExecutionEngineException

IAClass A = container.Resolve<IAClass>(); //throws System.ExecutionEngineException
Matt Ellen