繁体   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