我们在MongoDB上拥有的每个项目在另一个方面都会遇到无法加载的System.Runtime.InteropServices库的问题。

这次错误很有趣:

c# - 另一个System.Runtime.InteropServices错误-LMLPHP

外部异常找不到该库的版本4.3.0.0。
但是内部异常找不到版本4.0.0.0

有人对此有想法吗?

有关该问题的更多信息:

c# - 另一个System.Runtime.InteropServices错误-LMLPHP

因此,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>

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>

添加了关于版本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>

由于它声称使用路径4.3.0.0引用4.0.1.0

有些东西坏了,而且总是在同一个库中发生;不只是这个项目:在我包括MongoDB的任何地方,这个lib都是依赖项,每次都有一些随机的问题。

当我尝试手动加载时:
        var Name = new AssemblyName("System.Runtime.InteropServices.RuntimeInformation, Version=4.3.0.0");
        var Asm = Assembly.Load(Name);

它也会失败。

我发现System.Runtime.InteropServices.RuntimeInformation.dll不会复制到构建文件夹,即使它包含在项目中也是如此。

我发现了一个讨厌的解决方法:
如果我在主exe文件中包含MongoDB,即使我不使用它,它也依赖于Interop库,这迫使该库复制到build文件夹中,然后后续调用就可以了。

最佳答案

System.Runtime.InteropServices.RuntimeInformation v4.3.0 NuGet确实确实安装了版本为4.1.0.0的DLL。尽管令人困惑,但这似乎并没有造成任何问题。

尝试在直接或间接使用MongoDB v2.4.4的每个项目上安装以下NuGets

  • System.Runtime.InteropServices.RuntimeInformation v4.3.0
  • System.Runtime.InteropServices v4.3.0

  • 这对我有用。

    唯一不起作用的情况是MSTest单元/集成测试,其中MSTest似乎忽略了绑定(bind)重定向(单独的问题-似乎很常见),因此我使用常规控制台exe创建了集成测试。

    我可能还很遥远,但是我自己的经验/观察表明,MongoDB.Driver(v2.4.4)依赖于System.Runtime.InteropServices.RuntimeInformation,其对NETStandardLibrary的NuGet依赖关系可以满足,但是System.Runtime不会处理.InteropServices.RuntimeInformation对System.Runtime.InteropServices的依赖。这就是仅升级RuntimeInformation还是不够的。就我而言,我有许多项目已经依赖于NETStandardLibrary(v1.6),因此如果我想安装4.3.0并可以,则无法使用System.Runtime.InteropServices.RuntimeInformation v4.0.0。不能删除。我看到了您在不同时间看到的两个异常,并按上述方式安装了两个NuGet软件包,从而解决了它们。

    09-11 18:11