MongoDB client throws FileNotFoundException in mscorlib

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

My import for MongoDB

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

Code that executes:

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

Full error message:

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

Additional information: Failed to load the 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 specified file.

+16
source share
7 answers

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

+13
source

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

Good luck

+9
source

In my case, I already had System.Runtime.InteropServices.RuntimeInformation installed, but it continued to give me the same error. Either complained that 4.0.0.0 was not found, or if I updated app.config to 4.3, he complained that 4.3.0.0 was missing.

However, after uninstalling and reinstalling several packages, it started working, and although version 4.3 of System.Runtime.InteropServices.RuntimeInformation was installed, version 4.0.1.0 was required for app.config.

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

I have no idea why, but it finally works for me.

+6
source

After much experimentation, it seems that web.config requires the following:

 <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 NuGet redirects were, they were incorrect. Perhaps this is not a MongoDB problem per se, perhaps a problem with Microsoft Nuget packages / version.

+5
source

In my case, the package has already been installed. However, a version mismatch occurred in the web.config . Reinstalling the package fixed the problem. Open the package manager console and type:

 Update-Package System.Runtime.InteropServices.RuntimeInformation -Reinstall 
+2
source

I had the same problem. It took several minutes to find out that my problem was that I updated the nuget package "System.Runtime.InteropServices.RuntimeInformation" and it seems that the link to the MonghDb csharp driver has SpecificVersion = true.

Uninstall all nuget packages and install it again, or simply downgrade it to the same version as depending on the MongoDb driver.

Good luck

0
source

It looks crazy, but. I got this problem on Windows Server 2012 R2.

Only the installation of the latest updates helped. It was "A combination of safety and quality 2018-12 for .NET for Windows ..." (KB4471989).

0
source

Source: https://habr.com/ru/post/1259124/


All Articles