簡體   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