简体   繁体   English

加载后未找到另一个DLL的DLL依赖关系

[英]DLL dependency of another DLL not found though loaded

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. 在C#应用程序中,我正在加载用户在运行时提供的2个DLL(不是预先定义的引用),让它为A.dll,B.dll。 A.dll is referencing B.dll, but they are supplied separately. A.dll引用B.dll,但它们是单独提供的。 When I try to access a method from A.dll, with a parameter of type that is declared in B.dll, I get an: 当我尝试使用B.dll中声明的类型的参数从A.dll访问方法时,我得到:

"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.". “无法加载文件或程序集'B,版本= 1.0.0.0,文化=中性,PublicKeyToken =空”或其依赖项之一。系统找不到指定的文件。”。

error, although both DLLs were loaded. 错误,尽管两个DLL都已加载。 Even calling MethodInfo.GetParameters() will throw the exception. 即使调用MethodInfo.GetParameters()也会引发异常。

Tried to Load both DLLs with different methods: 尝试使用不同的方法加载两个DLL:

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

I set the reference in project A to B.dll as "Copy Local = false". 我在项目A中将对B.dll的引用设置为“ 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. A或B中任何不涉及上述连接的类型和方法的用法似乎都可以正常工作。

I made sure both assembly were loaded with AppDomain.CurrentDomain.GetAssemblies() (they both are). 我确保两个程序集都已加载AppDomain.CurrentDomain.GetAssemblies() (它们都是)。

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. 我必须假定我没有开发人员访问A.dll和B.dll项目(由用户提供)的权限,但是出于测试目的,我也可以尝试更改其中的内容。

Fusion log For A.dll: 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.

You are missing are probably missing another dependency of B.dll it. 您缺少的可能是缺少B.dll的另一个依赖项。 When you try to load a dll, Windows will try to look all dependency of it (other dlls). 当您尝试加载dll时,Windows将尝试查找它的所有依赖关系(其他dll)。 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. B.dll的所有依赖项也应复制到本地目录。

Use Dependency Walker .NET to find the missing dependencies. 使用Dependency Walker .NET查找缺少的依赖项。

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. 如果B.dll依赖于主程序所依赖的dll的较高版本,则有时无法使加载的较低版本的dll与B想要的较高版本一起工作。 In that case, you get this error. 在这种情况下,您会收到此错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM