0

This is strange...

In a project of mine I need to load external dll's at runtime. I've done this frequently before and I thought I had stepped on all the mines there where but this one has got the best of me so far.

It's very very basic really. I use Assembly.LoadFrom("c:\\test\\mytestlibrary.dll") but Fusion cannot find the file (I get a FileNotFoundException).

I have examined the fusion logs as usual and it just doesn't make sense. Are there some circumstances that would somehow prevent Fusion from finding a file even when I provide the complete and absolute path to it? I suspected the dll in question needed some other assembly but looking at the fusion logs doesn't indicate this. Besides, the test library references nothing that's not also referenced by the host assembly.

Any suggestions?

7
  • Does the test assembly reference different versions of anything vs the main assembly? Commented Apr 11, 2012 at 17:13
  • Does the target platform differ (32bit vs 64bit)? Commented Apr 11, 2012 at 17:14
  • 1
    And probably a stupid question, but are you absolutely 100% sure that the file C:\test\mytestlibrary.dll exists? Commented Apr 11, 2012 at 17:17
  • 2
    "Strange" problems like this require lots of details in your question so we don't have to ask a bunch of follow-up questions. Commented Apr 11, 2012 at 17:19
  • Have you actually verified that file is there by exact path you are trying to load it from? Commented Apr 11, 2012 at 17:19

1 Answer 1

1

Perhaps this blog entry by Suzzanne Cook will provide some clues?

For FileNotFoundException: At the bottom of the log will be the paths that Fusion tried probing for this assembly. If this was a load by path (as in Assembly.LoadFrom()), there will be just one path, and your assembly will need to be there to be found. Otherwise, your assembly will need to be on one of the probing paths listed or in the GAC if it's to be found.

You may also get this exception if an unmanaged dependency or internal module of the assembly failed to load. Try running depends.exe on the file to verify that unmanaged dependencies can be loaded. Note that if you re using ASP.NET, the PATH environment variable it's using may differ from the one the command line uses. If all of them could be loaded, try ildasm.exe on the file, double-click on "MANIFEST" and look for ".file" entries. Each of those files will need to be in the same directory as the manifest-containing file. -- http://blogs.msdn.com/b/suzcook/archive/2003/05/29/57120.aspx

IIRC, the fusion log should also show the list of paths sought. Is your path included? Further, is the assembly already loaded as a project reference or otherwise previously in the same app domain?

Sign up to request clarification or add additional context in comments.

4 Comments

Yes, I have examined the Fusion log but the thing is: When using Assembly.LoadFrom/LoadFile you specify the exact path to the assembly so there shoudl be no need for Fusion to start probing. In fact, using Assembly.LoadFrom/LoadFile is the common way to resolve probing issues when using the AppDomain approach to loading assemblies dynamically. Thanks anyway.
Well she wrote the thing. You say you examined the log - is it probing (and listing) other probe paths or not?
No, its not logging any paths, and that's what's so strange. Fusion starts probing examining the (host) app.config, machine.config file and so on, just like if I had initiated the load from a call to AppDomain.Load() rather than with Assembly.LoadFile().
You wrote just there "LoadFile" but we've been talking about "LoadFrom" so I suspect this was a slip. Have you tried Assembly.LoadFile which would bypass Fusion?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.