1

I'm using an external DLL to handle PDF exports in a C# project. I've added the external DLL reference in Visual Studio, added appropriate using statements, Intellisense shows all sorts of methods and properties when I type out the namespace, and the same is reflected in the object explorer.

However, when I run the application, the program throws a run-time exception because my external DLL can't find another DLL that lives in the same directory as the external DLL.

To make matters more confusing, the program doesn't complain if I just copy every single DLL from the directory of the one I want to reference into the Debug folder of my program, but obviously I shouldn't have to do this.

Thanks in advance.

Verbal Kint
  • 425
  • 1
  • 3
  • 20
  • Yes I think you need to look at properties of the dll under the references tab in solution explorer. Set to always copy or copy if newer. It should copy to the debug folder where you keep manually copying it anyway. – lozzajp Jul 21 '16 at 16:12

2 Answers2

0

What you need is to check "copy to output directory", "always copy" in the properties of your DLL in VS. Otherwise the DLL is not automatically copied in the output, and the program can not run.

I think this other question might help you: MSBuild doesn't copy references (DLL files) if using project dependencies in solution

Community
  • 1
  • 1
Ouarzy
  • 3,015
  • 1
  • 16
  • 19
  • Do you mean "Copy Local"? In which case it is already set to true – Verbal Kint Jul 21 '16 at 16:05
  • No I mean "Copy to the output directory" "always copy" – Ouarzy Jul 21 '16 at 16:20
  • I can't seem to find the option. In Visual Studio 2013, I open up Solution Explorer, expand the References dropdown, right click on my DLL, and choose Properties – Verbal Kint Jul 21 '16 at 16:27
  • Ok sorry I wasn't clear, I believed the DLL was in your csproj (added the same way as a file). In your case yes copy local should enough, is the dll in your output directory when you set it to true?) – Ouarzy Jul 21 '16 at 16:30
  • The DLL copies over fine, it just can't reference its own dependencies – Verbal Kint Jul 21 '16 at 16:49
  • Thanks for the link, this answer from a related question was pretty helpful: http://stackoverflow.com/questions/1132243/msbuild-doesnt-copy-references-dlls-if-using-project-dependencies-in-solution/21055664#21055664 – Verbal Kint Jul 21 '16 at 17:19
0

Looks like your dependency has another reference you want to include into your drop. You have two options: - Either add a reference to that implicit dependency as well (and set "Copy Local" = true) or - Add the dependent dll as a project item and mark it as "Copy to output directory" = true.

Artak
  • 2,819
  • 20
  • 31