【问题标题】:MongoDB client throws a FileNotFoundException in mscorlibMongoDB 客户端在 mscorlib 中引发 FileNotFoundException
【发布时间】:2017-03-15 01:44:29
【问题描述】:

我使用的是 Visual Studio .NET 4.6,Robomongo 连接到我的数据库没有问题

我对@9​​87654322@ 的导入

using MongoDB.Driver;
using MongoDB.Driver.Builders;
using MongoDB.Bson;

正在执行的代码:

MongoClient client = new MongoClient("mongodb://localhost");
MongoServer server = client.GetServer();
MongoDatabase mongoDatabase = server.GetDatabase("GameCollection");

完整的错误信息:

“System.IO.FileNotFoundException”类型的未处理异常 发生在 mscorlib.dll 中

附加信息:无法加载文件或程序集 'System.Runtime.InteropServices.RuntimeInformation,版本=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其之一 依赖关系。系统找不到指定的文件。

【问题讨论】:

    标签: c# mongodb database nosql


    【解决方案1】:

    安装缺少的软件包。使用 Package-installer,发出以下命令: 安装包 System.Runtime.InteropServices.RuntimeInformation

    【讨论】:

      【解决方案2】:

      在我的情况下,我已经安装了 System.Runtime.InteropServices.RuntimeInformation,但它一直给我同样的错误。要么抱怨找不到 4.0.0.0,要么如果我将 app.config 更新到 4.3,它抱怨缺少 4.3.0.0。

      但是,在卸载并重新安装几个软件包后,它开始工作,即使安装了 System.Runtime.InteropServices.RuntimeInformation 的 4.3 版,它也要求 app.config 具有 4.0.1.0

      <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>
      

      我不知道为什么,但它终于对我有用。

      【讨论】:

        【解决方案3】:

        经过大量实验,web.config 似乎需要以下内容才能工作:

        <dependentAssembly>
           <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
           <bindingRedirect oldVersion="0.0.0.0-4.1.2.0" newVersion="4.1.2.0" />
        </dependentAssembly>
        <dependentAssembly>
           <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
           <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
        </dependentAssembly>
        

        NuGet 放置的任何重定向都是不正确的。这本身可能不是 MongoDB 问题,可能是 Microsoft Nuget 包/版本标记的问题。

        【讨论】:

          【解决方案4】:

          我在这里遇到了同样的问题。花了几分钟才发现我的问题是我已经更新了 nuget 包“System.Runtime.InteropServices.RuntimeInformation”,而且似乎 MongoDb csharp 的驱动程序引用具有 SpecificVersion = true。

          删除所有 nuget 包并重新安装,或者将其降级到作为 MongoDb 驱动程序依赖项安装的相同版本。

          祝你好运!

          【讨论】:

            【解决方案5】:

            我在这里遇到了同样的问题。修复非常简单:编辑配置文件并在名称属性为“System.Runtime.InteropServices.RuntimeInformation”的节点“dependentAssembly”上,删除 publicKeyToken 属性。

            祝你好运

            【讨论】:

            • 它解决了这个问题。但你能告诉我为什么这能解决问题吗?我的意思是删除 publickToken 修复这对我来说很奇怪。
            • 发生这种情况是因为使用不同的 .snk 文件对 Robomongo 构建上编译的依赖程序集进行签名。删除公共令牌修复了绑定问题,并让它使用完全没有令牌的相同程序集。
            【解决方案6】:

            就我而言,该软件包已安装。但是,web.config 文件中的版本不匹配。重新安装包解决了这个问题。打开您的包管理器控制台并输入,

            Update-Package System.Runtime.InteropServices.RuntimeInformation -Reinstall
            

            【讨论】:

              【解决方案7】:

              看起来很疯狂,但是。 我在 Windows Server 2012 R2 中遇到了这个问题。

              只有安装最新更新才有帮助。 它是“2018 年 12 月 .NET for Windows 的安全和质量汇总...”(KB4471989)。

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2011-11-09
                • 2015-07-15
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多