MongoDB客户端在mscorlib中抛出FileNotFoundException

Hea*_*ild 16 c# database mongodb nosql

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

我为MongoDB导入的

using MongoDB.Driver;
using MongoDB.Driver.Builders;
using MongoDB.Bson;
Run Code Online (Sandbox Code Playgroud)

正在执行的代码:

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

完整的错误消息:

mscorlib.dll中发生了未处理的"System.IO.FileNotFoundException"类型异常

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

小智 13

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


小智 9

我在这里遇到了同样的问题.修复非常简单:编辑配置文件并在节点"dependentAssembly"中,其中name属性为"System.Runtime.InteropServices.RuntimeInformation",只需删除publicKeyToken属性即可.

祝好运


Tim*_*Tim 6

在我的情况下,我已经安装了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>
Run Code Online (Sandbox Code Playgroud)

我不明白为什么,但它最终适合我.


小智 5

经过大量的实验,似乎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>
Run Code Online (Sandbox Code Playgroud)

NuGet进行的任何重定向都不正确。这本身可能不是MongoDB的问题,也许不是Microsoft Nuget软件包/版本图章的问题。