0

In C# .NET 4.0 I am creating a class library / DLL that I plan to reuse in many other projects. This class library will use several DLLs itself. For example, the class library I am creating may reference several DLLs like:

ServerConnectorLibrary references:
Lib1.dll
Lib2.dll
Lib3.dll

When I build this, I get ServerConnectorLibrary.dll as the output in the bin\Debug folder.

What I want now is to use this ServerConnectorLibrary.dll in other projects. However, when I add the DLL to my new projects and run I get the following error:

FileNotFoundException: Could not load file or assembly "Lib1.dll".

If I add Lib1.dll to the bin\Debug folder of my new project, the problem is not solved.

leppie
  • 115,091
  • 17
  • 196
  • 297
John 'Mark' Smith
  • 2,564
  • 9
  • 43
  • 69
  • 1
    This is normal if ServerConnectorLibrary.dll references Lib1.Dll then it has a dependency on it so if you reference ServerConnectorLibrary.dll then you need to also reference Lib1.Dll and all other dependencies. Copying a dependent DLL into the Bin folder is not a good idea, reference it properly. – Ben Robinson Nov 19 '14 at 13:44
  • Thanks for the advice. In Visual Studio, my reference to the DLL is an absolute filepath. When I send my application to another computer, that computer will obviously not have the DLL. Exactly how do I reference it so that I can deploy the application and the DLLs? – John 'Mark' Smith Nov 19 '14 at 13:58
  • So long as all referenced DLLs have got `CopyLocal` set to true which is usually the default then they will be copied to the Bin directory when you compile you app. THe location they are on any given machine is not really relevant to deploying the app but they are relative paths in your project file, they just show as an absolute paths in the properties window. – Ben Robinson Nov 19 '14 at 14:02
  • Use Fuslogvw.exe to troubleshoot assembly resolution problems. – Hans Passant Nov 19 '14 at 14:34

1 Answers1

0

You may be able to combine all of your dependencies into a single assembly. Here is an old example on CodeProject.

http://www.codeproject.com/Articles/9364/Merging-NET-assemblies-using-ILMerge

There is also a StackOverflow thread here...

How do I merge multiple .net assemblies into a single assembly?

Otherwise, make sure the properties for each dependency is set to copy local and then include the dependencies along with your library. These are DLLs, so they are dynamically linked at run-time, unlike older C++ and C libraries that might be statically linked.

Community
  • 1
  • 1
Markus
  • 761
  • 3
  • 6