Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference unmanaged assembly

I'm trying to reference a managed DLL in my .NET project, without copying it into my output directory. So, when my program runs, it runs the DLL from the location it's installed - wherever that is. The problem lies in the fact that this managed DLL calls unmanaged DLLs. When I try and reference the managed DLL, it throws a FileNotFound Exception - Could not load file or assembly 'CharacterGen' or one of its dependencies. The system cannot find file specified. When I set my output to be within the same directory as the DLL I'm referencing, everything works fine. The usual solution would be to also reference the DLLs which are called from within the other assembly. However, I can't reference unmanaged assemblies from my managed program.

Is there a way to reference a managed DLL which calls unmanaged DLLs?

like image 762
XSL Avatar asked Jan 09 '12 19:01

XSL


1 Answers

If you asking how to get visual studio to copy the unmanaged DLL to your output directory you can do this:

  1. Add the unmanaged dll as a file or linked file in your project. (right click project -> add -> existing file then either Add or Add as Link).
  2. Select the file in the solution explorer. In the properties window set build action to copy always.
like image 185
insipid Avatar answered Sep 18 '22 15:09

insipid