gpt4 book ai didi

c# - 调用 dll 方法时出现 FatalExecutionEngineError

转载 作者:太空狗 更新时间:2023-10-30 01:09:49 26 4
gpt4 key购买 nike

在我的程序中这一行:

int value = MTEConnect(auth_string, err);

我收到这样的异常:

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 是这样导入的:

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

问题是什么以及如何解决?

upd:我可以在另一台机器上重现同样的问题,但我得到了更具描述性的信息:

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

库本身是有功能的,因为它可以在其他应用程序中使用,我只是不能在 c# 中使用它

最佳答案

我的问题解决了!代码不能这样工作:

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

但它确实是这样工作的:

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

看来缓冲区太短了。

关于c# - 调用 dll 方法时出现 FatalExecutionEngineError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6016243/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com