Oleg Vazhnev
Oleg Vazhnev

Reputation: 24067

FatalExecutionEngineError while calling dll method

In my program on this line:

int value = MTEConnect(auth_string, err);

I receive such exeption:

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 such a way:

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

What's the problem and how to fix it?

upd: I can reproduce the same problem on another machine, but I got a little more desriptive message:

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

Library itself is functional, because it can be used from another applications, I just can't use it from c#

Upvotes: 4

Views: 6880

Answers (2)

Oleg Vazhnev
Oleg Vazhnev

Reputation: 24067

I have solved my problem! Code doesn't work this way:

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

But it do work this way:

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

It seems buffer was too short.

Upvotes: 6

JaredPar
JaredPar

Reputation: 755457

A FatalExecutionEnigneError is often the result of corruption within the core CLR native code that leads to a fatal native exception. When it occurs at the site of a PInvoke call it's a big indicator the PInvoke signature is incorrect.

Could you provide the native signature so we can help diagnose this problem?

Upvotes: 1

Related Questions