开发者

Could not load assembly exception when using Assembly.LoadFile

here's my scenario:

I have three projects: two DLLs and one console application, let's name them foo.dll, bar.dll开发者_StackOverflow中文版 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:

  • All projects are strong named
  • Would prefer to not use the GAC
  • Bar.dll is in c:\bar.dll

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜