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=220.127.116.11, 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-18.104.22.168" newVersion="22.214.171.124" /> </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 126.96.36.199 (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.
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-188.8.131.52" newVersion="184.108.40.206" />
This means that the library, which was compiled with 220.127.116.11 will use version 18.104.22.168 at runtime.
User contributions licensed under CC BY-SA 3.0