简体   繁体   中英

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.

我认为托管C ++程序集缺少其他程序集或dll的引用。

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.

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.

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 (ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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