FatalExecutionEngineError when calling the dll method

In my program on this line:

int value = MTEConnect(auth_string, err); 

I get this exemption:

 FatalExecutionEngineError The runtime has encountered a fatal error. The address of the error was at 0x68c8a681, on thread 0x2334. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack. 

MTEConnect is imported this way:

  [DllImport("mtesrl.dll", CharSet = CharSet.Ansi)] private static extern int MTEConnect(String pars, StringBuilder err); 

What is the problem and how to fix it?

upd: I can reproduce the same problem on another machine, but I received a slightly more detailed message:

 Managed Debugging Assistant 'FatalExecutionEngineError' has detected a problem in 'C:\blahblah\MBClient\bin\Debug\MBClient.vshost.exe 

The library itself is functional, because it can be used from other applications, I just can not use it from C #

+4
source share
2 answers

I solved my problem! The code does not work as follows:

 StringBuilder err = new StringBuilder(); int value = MTEConnect(auth_string, err); 

But it works as follows:

 StringBuilder err = new StringBuilder(100); int value = MTEConnect(auth_string, err); 

The buffer seems to be too short.

+4
source

A FatalExecutionEnigneError often the result of corruption within the main CLR code, resulting in a fatal native exception. When this happens at the location of the PInvoke call, this is a large indicator, the PInvoke signature is incorrect.

Could you provide your own signature so that we can help diagnose this problem?

+1
source

All Articles