Failed to load assembly exception when using Assembly.LoadFile

here is my script:

I have three projects: two DLLs and one console application, name them foo.dll, bar.dll and console.exe. Console.exe downloads the file foo.dll using Assembly.LoadFile (@ "c: \ foo.dll"). The Foo.dll project has a link to bar.dll and uses the class. Console.exe loads foo.dll in order, the problem occurs when foo.dll tries to use the bar.dll class. I get "unable to load assembly:" bar.dll "blah blah exception.

Some moments:

  • All projects have strong names.
  • Prefers not to use the GAC
  • Bar.dll is located in the directory c: \ bar.dll

So, everything is in the same local directory referenced by the correct DLLs (via the project properties, and I used Reflector to make sure the build versions are correct). If I installed bar.dll in the GAC, everything will work as expected.

I think it has something to do with calling Assembly.LoadFile and makes the transition to the second DLL, but I'm not sure.

Thanks for your time and input.

+3
source share
1 answer

Assembly.LoadFile () should only be used in special circumstances. The compilation has no loading context, so bar.dll could not be found. The only real use cases are tools, programs that dump assembly metadata.

Load LoadFrom(). fuslogvw.exe

+4

Source: https://habr.com/ru/post/1777815/


All Articles