System.ExecutionEngineException Failure

江枫思渺然 提交于 2019-11-27 11:31:23

问题


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!


Based on answers this exception can be caused in multiple scenarios, mentioning htem in answer for better visibility.

List of possible causes/scenarios -

  • Argument mismatch between C++ and C#
  • While using reflection
  • WCF service tries to return an IList or IEnumerable here here
  • Using Profiling tools
  • using the std instruction in assembler
  • calling ::FreeLibrary() multiple times
  • .NET Clipboard calls
  • using the Unity Framework
  • Using the wrong marshaling
  • Using INotifyPropertyChanged

Possible workarounds/solutions -

  • Disable concurrent garbage collection

回答1:


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));



回答2:


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.




回答3:


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




回答4:


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.




回答5:


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.




回答6:


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.




回答7:


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.




回答8:


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.




回答9:


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




回答10:


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.




回答11:


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.




回答12:


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




回答13:


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




回答14:


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

Maybe that helps someone...




回答15:


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



回答16:


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.




回答17:


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. :-)




回答18:


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.




回答19:


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.




回答20:


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)




回答21:


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."




回答22:


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.




回答23:


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.




回答24:


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




回答25:


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




回答26:


  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



来源:https://stackoverflow.com/questions/967044/system-executionengineexception-failure

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