【发布时间】:2019-12-16 02:10:16
【问题描述】:
在一个 C# 应用程序中,我正在加载用户在运行时提供的 2 个 DLL(不是预定义的引用)让它成为 A.dll、B.dll。 A.dll 引用 B.dll,但它们是单独提供的。 当我尝试使用 B.dll 中声明的类型参数从 A.dll 访问方法时,我得到:
“无法加载文件或程序集'B,版本=1.0.0.0,文化=中性, PublicKeyToken=null' 或其依赖项之一。系统无法 找到指定的文件。”。
错误,虽然两个 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.
【问题讨论】:
-
A是否针对与提供的B不同的版本编译? -
无论如何enable fusion logging 在加载程序集失败时查看实际错误。
-
A 与 B 的相同版本编译。
-
融合日志作为编辑添加到原始帖子
标签: c# reflection