簡體   English   中英

從另一個DLL引用一個DLL-缺少依賴關系

[英]Referencing a DLL from another DLL - Missing Dependency

我有一個用C#編寫的DLL,可從第三方應用程序的上下文中運行作業。 該DLL需要引用另一個第三方DLL。 VS中的Intellisense效果很好,但在運行時會生成錯誤:“無法加載文件或程序集或其依賴項之一。系統找不到指定的文件。”

我運行了依賴性工具,發現缺少對mscorwks和perfcounter.dll的引用。 將這2個缺少的DLLS與第3方DLL放在同一文件夾中,可以更正依賴項工具中缺少的引用。

我不確定下一步該怎么做。 為了使DLL正常工作,所有這些文件都需要存放在哪里? 有趣的是,我還有一個獨立的可執行文件,該可執行文件引用了相同的第三方DLL,並且缺少引用也沒有任何問題。

接下來我應該嘗試什么?

編輯:下載了Fusion ++,這是來自日志的結果。 看起來找不到父對象。 在第三方應用程序的上下文中運行時,不確定如何將依賴的DLL指向正確的文件夾。

 *** Assembly Binder Log Entry (11/24/2019 @ 6:59:35 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:\\Program Files\\Autodesk\\Vault Professional 2020\\Explorer\\Connectivity.JobProcessor.Delegate.Host.exe --- A detailed error log follows. === Pre-bind state information === LOG: DisplayName = LicenseSpring, Version=4.7.0.0, Culture=neutral, PublicKeyToken=2d5c13cc31edbaaf (Fully-specified) LOG: Appbase = file:///C:/Program Files/Autodesk/Vault Professional 2020/Explorer/ LOG: Initial PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base = NULL LOG: AppName = Connectivity.JobProcessor.Delegate.Host.exe 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: Post-policy reference: LicenseSpring, Version=4.7.0.0, Culture=neutral, PublicKeyToken=2d5c13cc31edbaaf LOG: GAC Lookup was unsuccessful. LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Vault Professional 2020/Explorer/LicenseSpring.DLL. LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Vault Professional 2020/Explorer/LicenseSpring/LicenseSpring.DLL. LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Vault Professional 2020/Explorer/LicenseSpring.EXE. LOG: Attempting download of new URL file:///C:/Program Files/Autodesk/Vault Professional 2020/Explorer/LicenseSpring/LicenseSpring.EXE. LOG: All probing URLs attempted and failed. 

當您從磁盤(通過Browse )添加LicenseSpring.dll只是復制了該DLL並將其放置在package文件夾中。 但是VS對依賴的DLL一無所知。 讓我們考慮一下LicenseSpring.dll包含兩種方法。 第一種方法,做一些簡單的事情,並且不依賴於另一個DLL。 第二種方法取決於其他一些DLL。 如果您調用第一個方法-它將正常工作。 但是,當您嘗試執行第二種方法時-您會收到錯誤消息:

“無法加載文件或程序集或其依賴項之一...

如何解決這個問題:

  1. 從磁盤添加庫時,還需要添加所有依賴項。
  2. 您可以將程序集添加到GAC-但這將更加復雜

如果您無法找出運行時系統缺少什么程序集,則可以啟用FUSLOG( https://docs.microsoft.com/zh-cn/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-查看器 ),然后使用程序集綁定日志查看器找出缺少的內容。 說實話:FUSLOG不太舒適,但是效果很好。 完成后,別忘了禁用它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM