c# - DLLImport(C 代码) C# 试图读取或写入 protected 内存。这通常表明其他内存已损坏”

标签 c# c visual-studio-2010 dll

这是我的 DLL 导入语句:

[DllImport("KaracellLib.dll", EntryPoint = "karacell_bridge@8", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi, ExactSpelling = true)]
    public static extern int karacell_bridge(int argumentCount, string[] argContent);

native C 代码中的实际函数定义(已转换为 DLL):

int __stdcall karacell_bridge(int argumentCount, char ** argContent )

当我多次尝试在我的 C# 代码中调用 DLL 时,我收到了提到的错误。

我已经尝试了以下方法来解决错误

  1. 通过进入“工具”->“调试”->“常规”抑制模块加载时的 JIT 优化(仅管理)
  2. 在 C# dLL 导入定义中添加了 ref:public static extern int karacell_bridge(int argumentCount, ref string[] argContent);

感谢任何帮助!谢谢!

最佳答案

问题是因为多个线程正在调用 C# 程序中的 karacell_bridge 函数。因此,一旦我处理了它,异常就被修复了:)

关于c# - DLLImport(C 代码) C# 试图读取或写入 protected 内存。这通常表明其他内存已损坏”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12908266/

相关文章:

C# 通过属性名获取 Xelement 属性值

c# - 嵌套通用接口(interface)

c - 在C中的行尾添加字符

c - 我需要内存屏障吗?

c++ - devenv 和#define

c# - 在 Visual C# Express 2010 中编译时不包含代码更改

c# - Dot Net Core 和 Azure 存储 : Could not load file or assembly System, 版本=4.0.0.0

c# - 替代 C# 中的内联?

c++ - 位操作运算符优先级对输出的影响

c# - Eclipse 类似于 Visual Studio 2010 C# 中的控制台