Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - System.Runtime.InteropServices.RuntimeInformation constant annoyance with MongoDB

Tags:

c#

mongodb

We have a project made of a bunch of small tools.

All of them use MongoDB and there hasn't been one of them that hasn't annoyed me at one time or another with that error:

System.IO.FileNotFoundException occurred HResult=0x80070002
Message=Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

and all of them have an app.config file that I don't even know the origin of with the following content:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <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>
</assemblyBinding>

At the same time, NuGet has the following line:

  <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net462" />

So, obviously, I have the Interop lib version 4.3.0, but some file I have no clue about wants version 4.0.1.0 (note that there is not even the same number of digits). This is usually fixed by removing the lib, re-adding it and... soon, again, the same problem will come once more, usually after some NuGet updates, etc.

It seems to happen only on the projects where we have the MongoDB libs where the version number in NuGet gets out of sync with whatever creates the app.config file.

like image 290
Thomas Avatar asked Jun 29 '17 12:06

Thomas


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.

Is C language easy?

Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.

What is C language?

C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.


1 Answers

These binding redirects are necessary in those cases which has a version of the library targeting .NET Standard 2.0. .NET 4.6.2 didn't originally support .NET Standard 2.0 (it was released before .NET Standard 2.0), so there are additional DLLs that are needed to enable .NET Standard 2.0 support on .NET 4.6.2, and binding redirects are needed for those DLLs.

If you are able to target .NET 4.7.2, then you won't need these binding redirects. Also, check your visual studio version (otherwise some more dlls will get added to support old visual studio with .net version).

If you are not able to update your .NET version, then try to set proper bindingRedirect, instead of deleting this section from web.config.

<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.3.0.0" />

This means that the library, which was compiled with 4.0.1.0 will use version 4.3.0.0 at runtime.

like image 154
KushalSeth Avatar answered Sep 26 '22 01:09

KushalSeth