Reputation:
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 them here in the question for better visibility.
List of possible causes/scenarios:
INotifyPropertyChanged
Possible workarounds/solutions:
Upvotes: 38
Views: 54724
Reputation: 6743
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.
Upvotes: 4
Reputation: 13008
On my project I just discovered that using obfuscated DLLs can be a cause of this.
Here is the setup which caused the problem:
Visual Studio startup project produces a C# DLL. It is set to run an external program which will load said DLL + some others.
The external program is located under Program Files along with various .NET DLLs from our last build.
The build includes obfuscating DLLs (using ConfuserEX, though maybe any other obfuscation tool would cause the same problem if it obfuscated in the same way).
At runtime we would immediately get an ExecutionEngineException
(preceded by a "Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem..." message).
At that point looking in the Visual Studio Modules you could see that the DLL noted in the exception was being loaded from Program Files - e.g., it was the obfuscated DLL being loaded.
Replacing any of the obfuscated DLLs with their non-obfuscated equivalents disappeared the exception.
Beats me specifically why obfuscation would cause this exception, but I suspect that the debugger trying to attach is unable to reverse engineer the assembly, much like you can't easily decompile an obfuscated tool by any normal means. This was a case where running with CTRL+F5 (no debugger attached) would NOT have a problem.
Upvotes: 0
Reputation: 84765
I've come across this exception 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.
Upvotes: 2
Reputation: 1157
I am getting this exception in a .NET Framework 3.5 WPF application.
The exception occurs whenever the Close
method is called in the Loaded
window event. This occurs in a barebones window, as well.
However, the exception only occurs if I set the property SizeToContent="WidthAndHeight"
in the xaml
of the view. Removing this property fixes the issue.
I was also using the MVVM Light library. However, the exception occurs even after removing references to this library for this WPF window.
Upvotes: 0
Reputation: 118
Create new Web Forms Application
Open any page (lets say Default.aspx)
Add GridView to the form
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
Upvotes: 0
Reputation: 33
Using VS2015 ASP.NET Framework 4.5 I just had to rebuild and run again.
Upvotes: 0
Reputation: 2069
I get this error in a regular LINQ Query where I am returning FirstOrDefault using VS2010
Upvotes: 0
Reputation: 1164
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.
Upvotes: 0
Reputation: 340
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.
Upvotes: 0
Reputation: 8562
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."
Upvotes: 0
Reputation: 25897
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)
Upvotes: 0
Reputation: 263
One more case when System.ExecutionEngineException
is thrown is when an unhandled exception is thrown in delegate provided to ThreadPool.QueueUserWorkItem()
function.
Upvotes: 1
Reputation:
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.
Upvotes: 0
Reputation: 4283
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.
Upvotes: 2
Reputation: 26682
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.
Upvotes: 0
Reputation: 18567
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
Upvotes: 2
Reputation: 3549
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.
Upvotes: 2
Reputation: 15772
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.
Upvotes: 1
Reputation: 91
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));
Upvotes: 9
Reputation: 1077
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. :-)
Upvotes: 0
Reputation: 5383
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.
Upvotes: 0
Reputation: 41
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.
Upvotes: 4
Reputation: 11592
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
Upvotes: 0
Reputation: 93
I had this exception when running unmanaged code in a different version, than I compiled it with.
Maybe that helps someone...
Upvotes: 0
Reputation: 61
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.
Upvotes: 6
Reputation: 1209
There is a known bug when a WCF service tries to return an IList or IEnumerable.
Upvotes: 4
Reputation:
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
Upvotes: 0
Reputation: 123652
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.
Upvotes: 2