【问题标题】:C# - System.Runtime.InteropServices.RuntimeInformation constant annoyance with MongoDBC# - System.Runtime.InteropServices.RuntimeInformation 对 MongoDB 的持续困扰
【发布时间】:2017-12-03 03:52:37
【问题描述】:

我们有一个由一堆小工具组成的项目。

他们所有人都使用 MongoDB,并且没有一个没有一次或多次因该错误而惹恼我:

System.IO.FileNotFoundException 发生 HResult=0x80070002
消息=无法加载文件或程序集 'System.Runtime.InteropServices.RuntimeInformation,版本=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其之一 依赖关系。

它们都有一个我什至不知道其来源的 app.config 文件,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <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>
</assemblyBinding>

同时,NuGet 有如下一行:

  <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net462" />

所以,很明显,我有 Interop lib 4.3.0 版,但我不知道某些文件需要 4.0.1.0 版(请注意,甚至没有相同的位数)。 这通常是通过删除 lib,重新添加它来解决的......很快,同样的问题会再次出现,通常是在一些 NuGet 更新等之后。

这似乎只发生在我们拥有 MongoDB 库的项目上,其中 NuGet 中的版本号与创建 app.config 文件的任何内容不同步。

【问题讨论】:

    标签: c# mongodb


    【解决方案1】:

    在具有面向 .NET Standard 2.0 的库版本的情况下,这些绑定重定向是必需的。 .NET 4.6.2 最初不支持 .NET Standard 2.0(它在 .NET Standard 2.0 之前发布),因此需要额外的 DLL 才能在 .NET 4.6.2 上启用 .NET Standard 2.0 支持,并绑定重定向需要这些 DLL。

    如果您能够以 .NET 4.7.2 为目标,则不需要这些绑定重定向。此外,请检查您的 Visual Studio 版本(否则将添加更多 dll 以支持具有 .net 版本的旧 Visual Studio)。

    如果您无法更新您的 .NET 版本,请尝试设置正确的 bindingRedirect,而不是从 web.config 中删除此部分。

    <bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.3.0.0" />
    

    这意味着使用 4.0.1.0 编译的库将在运行时使用 4.3.0.0 版本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-12
      • 2016-10-18
      • 1970-01-01
      • 2013-03-26
      • 2014-12-26
      相关资源
      最近更新 更多