views:

129

answers:

4

I am getting an error back from a DLL saying it cannot create an instance of one of classes in my solution because it cannot find the assembly file.

If I am debugging a solution, do I need to put a copy of certain assembly files in other locations?

EDIT:

In my compiled solution all the DLLs (including the proprietary ones) all go in the app directory and it works fine. But I am trying to work out where the files should do in order to debug the solution.

A: 

I think you have forgotten to add reference of the assembly to the project.

Add the reference, and try again.

Read more here -> http://msdn.microsoft.com/en-us/library/7314433t%28VS.80%29.aspx

Nayan
Surely then it wouldn't compile?
David Archer
It does compile. I think the proprietary DLL needs the DLLs of my solution to be in a certain location but I don't what it is.
Craig Johnston
A: 

If they are in your references list, try right-clicking the problem reference in the solution explorer and selecting "properties". There is one property called copy local. Make sure that is true. Then when you build, a copy of that dll will be in your bin folder.

David Archer
A: 

You can add an event handler to AssemblyResolve to find out which library it tries to load. Some sample code and ideas can be get from this question.

Update
To find out, what is the best place for your project you should take a look into How the Runtime Locates Assemblies guide. Also to get a live view about where the framework searches for your needed dll you can use ProcessMonitor to see where it tries to catch it.

Oliver
I know which assembly it is trying to load because the Exception is telling me which one. I just don't know where to put the assembly. Should it go in the directory of the calling DLL?
Craig Johnston
@Craig: Yes, it should go in the same directory as the calling DLL, or the GAC. Otherwise it won't find it. See code4life's answer
Chris Lively
+1  A: 

Put the assembly in question in 1) the same directory, or 2) in the GAC, or 3) use AssemblyBinding to define the specific path that the .NET framework.

MSDN link: using AssemblyBinding to define the referenced assembly path

code4life
When you say "the same directory", what do you mean?
Craig Johnston
@Craig, I meant the referenced assembly should be in the same directory as the calling assembly.
code4life