C# 尝试读取或写入受保护的内存

C#在调用C++提供的dll的时候,报错“C# 尝试读取或写入受保护的内存 。这通常指示其他内存已损坏。”
System.AccessViolationException:“Attempted to read or write protected memory. This is often an indication that other memory is corrupt.”

[DllImport(xxxxx.dll)]

dll 异常导致程序崩掉,捕获不到异常,怎么处理啊,

试试动态加载调用DLL

[DllImport("xxx.dll", CallingConvention = CallingConvention.Cdecl)]
试试这样