开发者

Calling managed c++ directly from C# failed

Having A.dll which is a managed c++ project (no other dependencies) From B.dll which is a C# project where A.dll is referenced having a Nunit method foo(). If calling the managed c++ code f开发者_运维问答rom foo() I got FileNotFoundException:The specified module could not be found. (Exception from HRESULT: 0x8007007E).

I tried to change B.dll to console application and the same exception occurs. If I'm wrapping the managed c++ code in some other c# class in B.dll and then calling the wrapper from foo() everything works just fine.

The managed C++ is a static class where all of the functions arguments are managed types.

Ideas?

Thanks, Guy


This is not a managed DLL loading error, you can't see it in Fuslogvw.exe. I'd guess at an unmanaged DLL dependency for C++/CLI assembly that cannot be located. You'll be able to see Windows searching for the DLL with SysInternals' ProcMon utility.


use fuslogvw to see where it is trying to load the managed dll from. THis will tell you where you should put it.


You have to put the C++ DLL into the same folder of where your NUnit DLL lives, otherwise it wont find the C++ DLL to load.


OK,I think I got it, please correct me if I'm wrong.... Since I'm calling MC++ straight from C# code, some pre-load process "knows" that I'm calling MC++ thus trying to Load the MC++ and dependent C++ native libraries, since they are not in %PATH%, current Dir (the native libraries) it failed.

When I call the MC++ wrapped by C# class the loading phase is done later (I have a C# code that push into %PATH% the path of the native dll, in the former scenario this code is not even reached....) and thus succeed.

So my options are to put the native c++ path into the %PATH% constantly and not trying to do it in runtime (per the running process only).

Thoughts?

Guy

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜