views:

27

answers:

1

I'm getting a really weird FileNotFoundException thrown the first time I try to use a class defined in an assembly I have referenced. The assembly hasn't changed, and the location in the project file corresponds correctly to the physical path on disk.

This suddenly started failing in a solution that consists of two library projects, a windows service project and a console application, when I added installers to the windows service and a setup project. However, I have the console app as a single startup object, there are no references in either way between the console application and the service/installer projects.

+1  A: 

If you enable Assembly Binding Logging, you will find that the FileNotFoundException will contain within it the complete fusion probing log for the missing file. Normally this makes the problem pretty obvious straight away.

See http://msdn.microsoft.com/en-us/library/e74a18c4(VS.80).aspx

piers7
OK - I got the logger up and running, managed it to catch an exception, and found that the console app was looking for the "missing "assembly in its own output directory (\bin\Debug\) rather than where it should have been looking. I looked in the project file, found and deleted a reference to *another* dll, and suddenly this problem was solved. Don't ask me how, but it works. :P
Tomas Lycken
Where you reference an assembly from, and how the assembly is resolved at runtime are two totally different things, which surprises many people. The link above probably has the binding probe order referenced, but IRRC assemblies will be resolved from the GAC first, then the private bin path (bin/debug) before anywhere else.So if there's a copy of that assembly in that path (because it's a dependency of another dependency), that's where it'll be loaded from.
piers7