【问题标题】:How to solve the issue of "Native DLL libmbusmaster.dll is missing! Please deploy the DLL file into the same directory as mbusmaster.net.dll."如何解决“Native DLL libmbusmaster.dll is missing!请将DLL文件部署到与mbusmaster.net.dll相同的目录”的问题。
【发布时间】:2015-03-27 12:34:49
【问题描述】:

我在 .Net 中使用 FieldTalk Modbus。当我运行应用程序时,我在为 MbusTcpMasterProtocol 创建对象时遇到错误。

MbusTcpMasterProtocol mbusProtocol = new MbusTcpMasterProtocol();

错误是:

本机 DLL libmbusmaster.dll 丢失! 请将 DLL 文件部署到与 mbusmaster.net.dll 相同的目录中。

我将 libmbusmaster.dll 作为“ExistingItem”添加到项目中,并将 mbusmaster.net.dll 作为项目引用添加。

【问题讨论】:

  • 那么你确认这两个dll在同一个地方了吗? (以及您的应用程序加载它们的位置)
  • 是的,两者都在同一个位置(在 bin->debug 内),当我添加 libmbusmaster.dll 作为参考时,我收到错误为“D:\xxx\bin\Debug\libmbusmaster.dll”。无法添加 dll'。请确保该文件可访问,并且它是有效的程序集或 COM 组件。"
  • 因为我将“libmbusmaster.dll”添加为“ExistingItem(右键单击项目->添加-> ExistingItem)”

标签: c# c++ .net dll


【解决方案1】:

将“libmbusmaster.dll”添加到您的项目不会将其添加到“mbusmaster.dll”所在的同一文件夹中。您指定的 mbusmate.dll 位于“debug”文件夹中。当您将“libmbusmaster.dll”添加到项目中时,它可能已添加到项目的根文件夹中(而不是调试中)。要将其添加到调试中,请转到解决方案中“libmbusmaster.dll”的属性,然后选择“始终复制”或“如果更新则复制”。

【讨论】:

  • 感谢您的回复。我已经尝试使用“始终复制”选项,但运气不好,我遇到了同样的问题。它显示的路径为“D:\xxx\xxxService\libmbusmaster.dll”,不在“调试”文件夹中。
【解决方案2】:

mbusmaster.net.dll 使用相对 dll 导入 [DllImport("libmbusmaster.dll")]

这意味着它将尝试从入口程序集所在的位置加载 libmbusmaster.dll,而不是 mbusmaster.net.dll 所在的位置

对于大多数程序,入口程序集路径和 mbusmaster.net.dll 路径将是相同的。但是,如果您有一个应用程序说从其他文件夹加载插件,并且插件使用这些程序集,则该插件将不得不使用 here 中描述的 SetDllLocation 技术

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-22
    • 2021-11-21
    • 1970-01-01
    相关资源
    最近更新 更多