tags:

views:

77

answers:

4

Hi, 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 from 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

A: 

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.

Stan R.
It is not related to NUnit since the problem occurs even from simple Main()
Guy
i never said it was related to NUnit, it's related to wherever any DLL lives that wants to call the C++ DLL. Calling C# DLL is not enough, you need to place the C++ DLL in the same folder with any other DLL that calls the C# DLL. Meaning all 3 DLL's need to be in the same folder.
Stan R.
+1  A: 

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

pm100
A: 

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.

Hans Passant
Thank you so much! the problem indeed was a C++ unmanaged dll that was absent. Thanks, Guy.
Guy
A: 

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

Guy