DLL dependency of another DLL not found though loaded

0

In a C# application I'm Loading 2 DLLs provided by user during runtime (not a pre-difined reference) Let it be A.dll, B.dll. A.dll is referencing B.dll, but they are supplied separately. When I try to access a method from A.dll, with a parameter of type that is declared in B.dll, I get an:

"Could not load file or assembly 'B, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.".

error, although both DLLs were loaded. Even calling MethodInfo.GetParameters() will throw the exception.

Tried to Load both DLLs with different methods:

Assembly.Load(<Path>) 
Assembly.LoadFile(<Path>) 
Assembly.LoadFrom(<Path>)

I set the reference in project A to B.dll as "Copy Local = false".

Any usage of types and method from A or B which does not involve the connection described above seems to work fine.

I made sure both assembly were loaded with AppDomain.CurrentDomain.GetAssemblies() (they both are).

I have to presume I don't have developer access to A.dll and B.dll projects (provided by users), but for testing purpose I can try to change stuff in them as well.

Fusion log For A.dll:

*** Assembly Binder Log Entry  (8/10/2019 @ 11:47:04 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\Users\<username>\AppData\Local\JetBrains\Installations\ReSharperPlatformVs15_95cb26a8\JetBrains.ReSharper.TaskRunner.CLR45.x64.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = A, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///<project fullpath>/bin/Debug
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = C:\Users\<username>\AppData\Local\Temp\u5r0nb10.kwf\k2mn3yzp.umi
LOG: AppName = AppTest
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///<project fullpath>/bin/Debug/A.DLL.
LOG: Attempting download of new URL file:///<project fullpath>/bin/Debug/A/A.DLL.
LOG: Attempting download of new URL file:///<project fullpath>/bin/Debug/A.EXE.
LOG: Attempting download of new URL file:///<project fullpath>/bin/Debug/A/A.EXE.
LOG: All probing URLs attempted and failed.
c#
reflection
asked on Stack Overflow Aug 8, 2019 by Ziv • edited Aug 10, 2019 by Ziv

2 Answers

0

You are missing are probably missing another dependency of B.dll it. When you try to load a dll, Windows will try to look all dependency of it (other dlls). Unfortunately, the error you see will be:

"The system can not find the specified"

All dependencies of B.dll should be also copied to the local directory.

Use Dependency Walker .NET to find the missing dependencies.

answered on Stack Overflow Aug 8, 2019 by EylM
0

Since everything is "there" I've got another possibility. Normally, this is obscure, but it can happen.

If B.dll depends on a higher version of a dll that your main program depends on, sometimes the lower version dll you loaded can't be made to work with the higher version B wants. In that case, you get this error.

answered on Stack Overflow Aug 10, 2019 by Joshua

User contributions licensed under CC BY-SA 3.0