繁体   English   中英

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

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

在C#应用程序中,我正在加载用户在运行时提供的2个DLL(不是预先定义的引用),让它为A.dll,B.dll。 A.dll引用B.dll,但它们是单独提供的。 当我尝试使用B.dll中声明的类型的参数从A.dll访问方法时,我得到:

“无法加载文件或程序集'B,版本= 1.0.0.0,文化=中性,PublicKeyToken =空”或其依赖项之一。系统找不到指定的文件。”。

错误,尽管两个DLL都已加载。 即使调用MethodInfo.GetParameters()也会引发异常。

尝试使用不同的方法加载两个DLL:

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

我在项目A中将对B.dll的引用设置为“ Copy Local = false”。

A或B中任何不涉及上述连接的类型和方法的用法似乎都可以正常工作。

我确保两个程序集都已加载AppDomain.CurrentDomain.GetAssemblies() (它们都是)。

我必须假定我没有开发人员访问A.dll和B.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.

您缺少的可能是缺少B.dll的另一个依赖项。 当您尝试加载dll时,Windows将尝试查找它的所有依赖关系(其他dll)。 不幸的是,您看到的错误将是:

“系统找不到指定的”

B.dll的所有依赖项也应复制到本地目录。

使用Dependency Walker .NET查找缺少的依赖项。

由于一切都是“有”的,所以我还有另一种可能性。 通常,这是晦涩的,但可能会发生。

如果B.dll依赖于主程序所依赖的dll的较高版本,则有时无法使加载的较低版本的dll与B想要的较高版本一起工作。 在这种情况下,您会收到此错误。

暂无
暂无

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

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