相关疑难解决方法(0)

又一个System.Runtime.InteropServices错误

我们与MongoDB一起使用的每个项目都会在没有加载的System.Runtime.InteropServices库中出现问题.

这次错误很有趣:

互操作加载异常

外部异常找不到lib的4.3.0.0版本.但是内部异常找不到版本4.0.0.0

有没有人对此有所了解?


有关此问题的更多信息:

在此输入图像描述

所以,NuGet已经安装了4.3.0.0

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="System.Runtime" version="4.3.0" targetFramework="net462" />
  <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net462" />
</packages>
Run Code Online (Sandbox Code Playgroud)

packages.config确认我已经安装了4.3.0.0,

然而,app.config似乎总是与现实不同步:

  <dependentAssembly>
    <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0" />
  </dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

添加了关于版本4.0.1.0的一行

在同一行.. csproj是胡说八道:

<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>x:\Packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>
Run Code Online (Sandbox Code Playgroud)

因为它声称引用4.0.1.0的路径为4.3.0.0

有一些东西被破坏了,它总是发生在那个完全相同的lib上; 不仅仅是这个项目:在我包含MongoDB的任何地方,这个lib都是一个依赖项,每次都有一些随机问题.

当我尝试手动加载时:

        var Name = new AssemblyName("System.Runtime.InteropServices.RuntimeInformation, Version=4.3.0.0");
        var Asm = Assembly.Load(Name);
Run Code Online (Sandbox Code Playgroud)

它也失败了.

我发现System.Runtime.InteropServices.RuntimeInformation.dll不会被复制到build文件夹,即使它包含在项目中.


我找到了一个讨厌的解决方法:如果我在主exe中包含MongoDB,即使我不使用它,它依赖于Interop lib,这迫使lib被复制到build文件夹,然后后续调用工作.

.net c# interop windows-runtime

10
推荐指数
1
解决办法
5408
查看次数

标签 统计

.net ×1

c# ×1

interop ×1

windows-runtime ×1