简体   繁体   中英

Could not load .Net assembly that has unmanaged dependencies

We have bought a library which does some signal processing.

This library is written in C++ and it provides two .Net wrappers.

If we reference only the .Net wrapper, we are able to build, but when running it, we receive an exception, telling us that it can't find the c++ dlls.

If I copy the Native dlls manually, everything works fine.

What is the best way to handle this issue? I mean, to have automatically copied that C++ dll file in the output directory of our project by referencing this .NET wrapper dll only.(This library is being used in several projects, which are used in different windows applications).

We can't add C++ dll as reference, since they are not managed code.

For the example, let's say that my project has the following architecture:

/
  Src/
    ApplicationA/
      ProjectAUsingReference/
    ApplicationB/
      ProjectBUsingReference/
  Lib/
    /LibXYZ
      WrapperDll.dll
      UnManagedDllOne.dll
      UnManagedDllTwo.dll

All my applications have the same output path, but we can build only the application A, or only the application B. So an additional goal would be to not copy if the file already exists(with the same date/size?)

Three ways to solve this issue:

  1. Create a Post-build event in each project which references the managed dlls. The Post-build event will have copy command to copy the native dlls from source to destination.
  2. Add your unmanaged dlls as link to your projects and mark it to copy to output directory. (these two already said in comment by GoodGuyStoft)
  3. If your project is inhouse, add the DLL path to PATH variable, it works without much modification. Remember to deploy your native dlls along with your project.

Regards Kajal

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