18

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.

Community
  • 1
  • 1
HealdGuild
  • 181
  • 1
  • 1
  • 5

7 Answers7

16

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

Galo Cego
  • 161
  • 1
  • 4
  • It fixes the problem. but could u tell me why this solves the problem? I mean removing a publickToken fixes this is weird for me. – SomeGuyWhoCodes Aug 14 '19 at 08:30
  • That happens because a different .snk file was used to sign the compiled dependent assembly on Robomongo build. Removing the public token fixes the bind problem and let It use the same assembly with no token at all. – Galo Cego Aug 24 '19 at 12:33
  • Thank you!!! I already wanted to rewrite the application – Stepagrus Dec 27 '22 at 13:05
14

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

user3096476
  • 232
  • 1
  • 5
6

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

However, after uninstalling and reinstalleding several packages it started working, and even though version 4.3 of the System.Runtime.InteropServices.RuntimeInformation was installed, it required the app.config to have 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>

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

Tim
  • 606
  • 4
  • 7
6

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.

Kunal
  • 125
  • 1
  • 5
4

In my case, the package was already installed. However, there was a mismatch of the versions in the web.config file. A reinstall of the package fixed the issue. Open your Package Manager Console and type in,

Update-Package System.Runtime.InteropServices.RuntimeInformation -Reinstall
Earlee
  • 338
  • 4
  • 17
0

I had the same problem here. It took a few minutes do find out that my problem was the fact that I have updated the nuget package "System.Runtime.InteropServices.RuntimeInformation", and it seems that MongoDb csharp's driver reference's has SpecificVersion = true.

Remove all nuget packages and install it again , or just downgrade it to the same version that it's installed as a MongoDb driver dependency.

Good luck!

ibirite
  • 485
  • 4
  • 5
0

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

Only installation latest updates did help. It was "2018-12 Security and Quality Rollup for .NET for Windows..." (KB4471989).