从另一个DLL引用一个DLL-缺少依赖项

问题描述 投票:0回答:2

我有一个用C#编写的DLL,它可以在第三方应用程序的上下文中运行作业。该DLL需要引用另一个第三方DLL。 VS中的Intellisense效果很好,但是在运行时会生成错误:“无法加载文件或程序集或其依赖项之一。系统找不到指定的文件。”

我运行了依赖工具,发现缺少对mscorwks和perfcounter.dll的引用。将这两个缺少的DLLS与第三方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.
c# dll
2个回答
0
投票

[当您从磁盘添加LicenseSpring.dll(通过Browse)时-VS刚刚复制了该DLL并将其放置到包文件夹中。但是VS对依赖的DLL一无所知。让我们考虑LicenseSpring.dll包含两种方法。第一种方法,做一些简单的事情,并且不依赖于另一个DLL。第二种方法取决于其他一些DLL。如果您调用第一个方法-它将正常工作。但是,当您尝试执行第二种方法时-您会收到错误:

“无法加载文件或程序集或其依赖项之一...

如何解决此问题:

  1. 从磁盘添加库时,您还需要添加所有依赖项。
  2. 您可以将程序集添加到GAC-但这会更加复杂

0
投票

如果无法找到运行时系统缺少的程序集,则可以启用FUSLOG(https://docs.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer)并使用程序集绑定日志查看器来查找缺少的程序集。老实说:FUSLOG不太舒适,但是效果很好。完成后,别忘了禁用它。

© www.soinside.com 2019 - 2024. All rights reserved.