【问题标题】:How to resolve file not found when loading interop dll with .net core 3.0?使用 .net core 3.0 加载互操作 dll 时如何解决找不到文件?
【发布时间】:2019-10-22 12:28:02
【问题描述】:

我正在尝试将一些代码从 .net frame 4.7.1 移植到 .net core 3.0。

问题是我们有一个 C++ COM 程序集,我们使用清单在 .net 项目中引用它。

我已将项目添加到新解决方案并添加了参考。创建了一个互操作 dll,但是当我尝试运行代码时出现异常

{"Could not load file or assembly 'Interop.MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.":"Interop.MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"}

该文件位于项目的输出文件夹中。实际的 com 程序集不是,但即使复制它也不起作用。

【问题讨论】:

  • COM 是特定于 windows 的,我怀疑它与 .Net 核心的兼容性,它也需要与 Linux 和 Mac 一起使用。
  • 这不起作用,因为 MSBuild 的 .net 核心版本无法构建项目。错误:MSB4803:.NET Core 版本的 MSBuild 不支持任务“ResolveComReference”。

标签: c# .net dll com


【解决方案1】:

事实证明,在 Visual Studio 中添加引用不适用于 .net 核心应用。

解决方案是创建一个 .net 框架应用,添加引用,然后将 csproj 的参考部分复制到您的 .net 核心项目中。

【讨论】:

    【解决方案2】:

    嵌入互操作类型!!!带我永远找到这个......!

    <Reference Include="Microsoft.Office.Interop.Excel, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c">
      <HintPath>Microsoft.Office.Interop.Excel.dll</HintPath>
      <EmbedInteropTypes>True</EmbedInteropTypes>
    </Reference>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      • 1970-01-01
      • 2019-08-21
      • 1970-01-01
      相关资源
      最近更新 更多