gpt4 book ai didi

C# - System.Runtime.InteropServices.RuntimeInformation 对 MongoDB 的持续困扰

转载 作者:行者123 更新时间:2023-12-03 16:28:22 30 4
gpt4 key购买 nike

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

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

System.IO.FileNotFoundException occurred HResult=0x80070002
Message=Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.



他们都有一个 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(请注意,甚至没有相同的位数)。
这通常是通过删除库,重新添加它来解决的,然后......很快,同样的问题会再次出现,通常是在一些 NuGet 更新等之后。

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

最佳答案

在具有面向 .NET Standard 2.0 的库版本的情况下,这些绑定(bind)重定向是必需的。 .NET 4.6.2 最初不支持 .NET Standard 2.0(它在 .NET Standard 2.0 之前发布),因此需要额外的 DLL 才能在 .NET 4.6.2 上启用 .NET Standard 2.0 支持,并绑定(bind)重定向这些DLL需要。
如果您能够以 .NET 4.7.2 为目标,则不需要这些绑定(bind)重定向。此外,检查您的 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 版本。

关于C# - System.Runtime.InteropServices.RuntimeInformation 对 MongoDB 的持续困扰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44825245/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com