简体   繁体   English

从托管C ++ DLL使用C#程序集时崩溃

[英]Crash when using C# Assembly from Managed C++ DLL

On a Windows XP system, I'm writing a Mangaged C++ library which calls code in a C# Assembly. 在Windows XP系统上,我正在编写一个Mangaged C ++库,该库在C#程序集中调用代码。 Unfortunately, as soon as I start referencing a symbol in the C# Assembly, running the Managed C++ library fails with this error (I copied this from the XP crash dialog): 不幸的是,一旦我开始在C#程序集中引用一个符号,运行Managed C ++库就会失败,并显示以下错误(我从XP崩溃对话框中复制了此代码):

EventType : clr20r3
P1 : treeviewdemo.exe
P2 : 0.0.0.0
P3 : 4a5d6d62
P4 : system.windows.forms
P5 : 2.0.0.0
P6 : 4889dee7
P7 : 12fc     
P8 : ac
P9 : system.io.filenotfoundexception    

The Manged C++ library is basically just: Manged C ++库基本上只是:

#using "C:\\MyCSharpAssembly.dll";

__declspec(dllexport) void callMangagedCode() {
  ManagedObject ^o = nullptr;
}

The '#using' itself doesn't seem to cause any problem, but as soon as I start using symbols form the C# DLL, I get problems. '#using'本身似乎不会引起任何问题,但是一旦我开始使用C#DLL中的符号,就会遇到问题。 Does anybody know what's going on? 有人知道发生了什么吗?

The system.io.filenotfoundexception part makes me think that some DLL is not being found, but I have no idea which or where it's looking. system.io.filenotfoundexception部分使我认为未找到某些DLL,但是我不知道它在寻找哪个或在哪里。

Are all the dependencies of MyCSharpAssembly.dll available on the same path? MyCSharpAssembly.dll所有依赖项MyCSharpAssembly.dll在同一路径上可用吗? If you are not sure, try loading the C-Sharp Assembly in ILDasm Tool to find out what are its dependencies. 如果不确定,请尝试在ILDasm工具中加载C-Sharp组件,以了解其依赖性。

As a sanity check, also check that whether this C-Sharp DLL can be loaded from another C-Sharp executable or not. 作为健全性检查,还要检查是否可以从另一个C-Sharp可执行文件加载此C-Sharp DLL。

file no found? 找不到文件?

the C# Assembly no found? C#程序集找不到?

copy it to windows or system32 and have a try 将其复制到Windows或system32并尝试

if failure,try to register 如果失败,请尝试注册

Do you have access to the C# assemblies source code? 您可以访问C#程序集源代码吗? Can you run your managed C++ code in the debugger? 您可以在调试器中运行托管的C ++代码吗? It would be worthwhile to see a stack trace of the exception, this might give you more hints as to what is happening when the exception occurs. 值得一提的是看到异常的堆栈跟踪,这可能会给您更多有关异常发生时发生情况的提示。

I'd suspect that the crash may be related to the operation you're doing. 我怀疑崩溃可能与您正在执行的操作有关。 As Aamir mention, the other possibility may be a dependency of the C# assembly... 正如Aamir所提到的,另一种可能性可能是C#程序集的依赖性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM