"FileNotFoundException" exception thrown because of "Copy local = false"

335 Views Asked by At

I have about 20 solutions with 5-10 projects each and they reference each other and some 3rd party libraries as well. I have an Output folder, were all of them are built. So I don't want to have any copies of each assembly that is being referenced (that's what the requirements are). So I've set the Copy local to false for every reference in one of the projects and it didn't throw an error at compile time. But at run-time it threw FileNotFoundException, saying "Could not load file or assembly 'X' or one of its dependencies. The system cannot find the file specified." As I've read in this and this thread, you could specify the paths for the CLR to search, but they have to be sub folders of the application base folder, and since I have 10 windows services, that means that I'll have to copy the referenced assemblies in each service's base folder (which is not the point).

One thing I've noticed is that when project A has a reference to project B, not only B.dll is being copied, but also C.dll (being referenced from B), D.dll etc. And the strange thing is when I set Copy local to false for reference B and I delete the copy of B.dll there is no problem - it manages to find it in the Output directory, but when I delete the copy of C.dll (or D.dll) that's when the problem occurs. So I set Copy local to false for the C reference in project B, but it didn't help.

Does anybody have and idea why is this happening?

1

There are 1 best solutions below

2
On

You have to either:

  • Save them in the GAC, so every app can find the referenced assemblies;
  • Implement an event handler for AppDomain.AssemblyResolve to find the assemblies yourself;
  • Copy all assemblies in the build script to the right folders, or use one central folder.