Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB client throws a FileNotFoundException in mscorlib

I'm using Visual Studio .NET 4.6 and Robomongo has no problem connecting to my database

My imports for MongoDB

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

The code that's executing:

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

The full error message:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

Additional information: Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

like image 784
HealdGuild Avatar asked Nov 01 '16 20:11

HealdGuild


3 Answers

Install the missing package. Using Package-installer, issue following command: Install-Package System.Runtime.InteropServices.RuntimeInformation

like image 157
user3096476 Avatar answered Nov 06 '22 11:11

user3096476


I had the same problem here. The fix is pretty simple: edit the config file and on the node "dependentAssembly" where name attribute is "System.Runtime.InteropServices.RuntimeInformation", just remove the publicKeyToken attribute.

Good Luck

like image 13
Galo Cego Avatar answered Nov 06 '22 09:11

Galo Cego


After much experimentation, it seems web.config needs the following to work:

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

Whatever redirects NuGet was putting there were incorrect. This maybe isn't a MongoDB issue per se, perhaps issue with Microsoft Nuget packages/version stamps.

like image 6
Kunal Avatar answered Nov 06 '22 11:11

Kunal