Reputation: 183
here's my scenario:
I have three projects: two DLLs and one console application, let's name them foo.dll, bar.dll and console.exe. Console.exe loads foo.dll using Assembly.LoadFile(@"c:\foo.dll"). Foo.dll's project has a reference to bar.dll and makes use of a class. Console.exe loads foo.dll fine, the problem occurs when foo.dll tries to use bar.dll's class. I get a "could not load assembly: "bar.dll" blah blah exception.
Some points:
So everything is in the same local directory, the correct dlls are being referenced (via project properties, and I've used Reflector to make sure the assembly versions are correct). If I install bar.dll to the GAC everything works as expected.
I think it has something to do with the Assembly.LoadFile call, and making a hop to the second DLL, but I'm not sure.
Thanks for your time and input.
Upvotes: 4
Views: 1644
Reputation: 941545
Assembly.LoadFile() should only ever be used in very special circumstances. The assembly doesn't have a loading context, that's why bar.dll cannot be found. The only real use case is tooling, programs that dump assembly metadata.
Use Load or LoadFrom(). Troubleshoot problems with fuslogvw.exe
Upvotes: 5