System.ExecutionEngineException Failure

隐身守侯 提交于 2019-11-28 18:36:38

This should not be taken too seriously, but I managed to get this exception while having some fun with reflection:

typeof(IntPtr).GetField("Zero").SetValue(null, new IntPtr(666));

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.

I encountered it when calling a function in an unmanaged library when my managed code was compiled for release. The error goes away when compiled for debugging.

Alexandre Brisebois

Quoted from the MSDN reference page for System.ExecutionEngineException:

The exception that is thrown when there is an internal error in the execution engine of the common language runtime. This class cannot be inherited.

There is no non-obsolete alternative to ExecutionEngineException. If further execution of your application cannot be sustained, use the FailFast method.

Tip

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.

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.

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.

Brian Kennedy

I am getting this ExecutionEngineException when just using standard .NET Clipboard calls. My code is 100% managed. So, it seems the .NET Framework has issues.

PastedData = Clipboard.GetDataObject();
object imageObj = PastedData.GetData(dataType);

where data type is "EnhancedMetafile", which was in the list of formats on the Clipboard.

update your application to .net 4.0 OR 4.5 because that exception is obsolete. "Note: This API is now obsolete." see: http://msdn.microsoft.com/en-us/library/system.executionengineexception(v=vs.100).aspx

Brent

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.

I've just come across this exception while working on WPF application. VS showed that it happened while notifying property change through NotifyPropertyChanged call(INotifyPropertyChanged).

Looks very strange to me and it happened only once; it stopped the debugging session and didn't happened after running the application again.

Mita

One more case when System.ExecutionEngineException is thrown is when an unhandled exception is thrown in delegate provided to ThreadPool.QueueUserWorkItem() function.

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

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

Maybe that helps someone...

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

I get this Exception when viewing pdf files with an external viewer. I think the viewer itself is the root of all evil. It has to be something outside of the .NET framework obviously.

Using the wrong marshaling causes me this exception. I've had a pure C *.dll to use; I write a wrapper around it in C#, using DllImport; then I used marshaling to let out string parameters to fill a StringBuilder, like this:

    [DllImport("old.dll", CallingConvention = CallingConvention.Winapi, CharSet = CharSet.Ansi)]
    public static extern UInt32 GetMessage([MarshalAs(UnmanagedType.LPStr)] out StringBuilder message);

Using UnmanagedType.LPStr causes me that exception; using UnmanagedType.BStr, the right string marshal in this case, solved me the problem. Just my 2 cent. :-)

I managed to get this exception while debugging a C# 4.0 web application which uses an assembly that uses an Azure service bus. This assembly has a bug where it will try to loop forever to receive a message from a closed servicebus, but the exception handler captures that exception. However, while debugging the code, it actually killed Visual Studio 2012 with this exception! Yes, VS2012 was the one that threw the exception.

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.

Adam Tegen

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)

I'll add how I hit this.

Using .Net 4 code contacts, a Contract.Ensures(Contract.Result<object>() != null) will throw this exception IIF you have Assert on Contract Failure check in the project properties page for Code Contracts. Disabling this checkbox doesn't disable the check however. You get the expected "Post condition failed message."

I got this error when I moved a harddisk from one computer to another (win 8 reinstalled drivers automatically ) but I suspect the native gened exes will not work.

Getting this problem in pure managed WPF app in a pretty innocent situation it seems to me. I have a control in a grid which I want to display or hide so I'm setting it's visibility to Visibility.Collapsed or Visibility.Visible. It starts out collapsed. I press a button and it gets set to visible and appears just fine. I press another button and set it to collapsed and boom - big ugly error. Nothing fancy or all that unusual. This is using 4.5. Very odd. When I look at the data for the error it says System.Collections.EmptyReadOnlyDictionaryInternal.

I get this error in a regular LINQ Query where I am returning FirstOrDefault using VS2010

Using VS2015 ASP.NET Framework 4.5 I just had to rebuild and run again.

  1. Create new Web Forms Application

  2. Open any page (lets say Default.aspx)

  3. Add GridView to the form

  4. Click on the GridView, then on the little arrow (upper right corner). When I click "Edit columns" or "Add new column" or Data Source > New Data Source, Visual Studio 2015 crashes with System.ExecutionEngineException in mscorlib.dll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!