martin
martin

Reputation:

Using managed C++ dll from C#

I've created a dll using managed C++. Now I'm trying to use it from C#. I've added the Object to project references. Object browser shows the object in the dll correcly, path to the dll in object browser corresponds to the actual path.

However, when I run the C# program it complains:

Unhandled Exception: System.IO.FileNotFoundException: The specified module could not be found. (Exception from HRESULT: 0x8007007E)

Any idea what else have to be done?

Thanks.

Upvotes: 5

Views: 3980

Answers (4)

Martin Gunia
Martin Gunia

Reputation: 1141

Check that the c++ assembly is present in the same folder as your c# program. It should be copied over automatically if the 'Copy Local' property is set to true (on the reference to the c++ dll in your c# app).

If the c++ dll is there, the most likely problem is that the c++ dll depends on another non-managed dll which cannot be found (i.e. c# will not copy these to your app folder because it does not know about unmanaged references). You can use DependencyWalker on the c++ dll to check for missing dependencies.

Another probable couse could be a problem with your MSVC runtime dlls. see if DependencyWalker complains about missing MSVCR*.dll, MSVCP*.dll etc... files.

Upvotes: 0

Quintin Robinson
Quintin Robinson

Reputation: 82335

Are you running the application in release on a machine without VS installed?

I only ask because I ran into a similar problem here: Mixed Mode Library and CRT Dependencies - HELP

if you scroll down to my answer you can see what I did that helped me.

Upvotes: 0

Stu Mackellar
Stu Mackellar

Reputation: 11638

Does your managed C++ assembly have an other dependencies, including unmanaged dlls? You'll see this error at runtime if your referenced assembly fails to load a dependency.

Upvotes: 0

plinth
plinth

Reputation: 49189

I think that you're missing the other assemblies or dll's references by your managed C++ assembly.

Upvotes: 6

Related Questions