1

I know this is asked a lot, but I tried every solution and didn't work!

This is the error when running in debug mode:

System.IO.FileLoadException: '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 located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

I tried removing all the bin and obj folders for all the projects in my solution. also removed the Packages folder.

also removed this entry in all the config files:

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

also changed newVersion value in above code to 4.0.0.0 but in no way it likes to work!

When I unload the project, and edit it, I see this line:

<Reference Include="System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
  <HintPath>..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll</HintPath>
</Reference>

How can I solve this problem? Thanks in advance.

Blendester
  • 1,583
  • 4
  • 19
  • 43
  • Please, read [documentation](https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/bindingredirect-element). Perhaps, there's an answer. – JohnyL Dec 30 '17 at 11:50
  • @JohnyL ok, I changed it as follows: `oldVersion="0.0.0.0-4.0.1.0" newVersion="4.3.0.0"` , same error. – Blendester Dec 30 '17 at 12:09
  • What runtime are you using - project target? Are you running from Visual Studio - which version? Do you get the same running the exe directly from windows explorer? Try fusion log to see what getting loaded: https://learn.microsoft.com/en-us/dotnet/framework/tools/fuslogvw-exe-assembly-binding-log-viewer – Andez Dec 30 '17 at 12:56
  • Few things doesn't seem to match here. In your config files, it suggest that it referencing version 4.0.1.0 -- and when you unload the project, it hinted that version is in a folder with version 4.3.0. However, the one that was missing was actually version 4.0.0.0. --> If you are using some package manager, try to load version 4.0.0.0 instead of the newer version? – hsoesanto Dec 30 '17 at 13:08
  • @hsoesanto installed version `4.0.0.0` using NuGet package manager, didn't help. – Blendester Dec 30 '17 at 14:07
  • Did you still get the same error message? I'm assuming since you install using nuget package manager -- you would be able to see the version 4.0.0.0 in the packages folder now? When you edit the project -- what is the reference that it tries to include? is it now 4.0.0.0 or still 4.0.1.0? Would removing the line ..\packages\... helps? – hsoesanto Dec 30 '17 at 14:11
  • @Blendester, Are you using MongoDB? If yes, what is the version? This is a bug for MongoDB 2.4.0-beta1, and it fixed at 2.4. If you are already in the 2.4 version, please try to install `System.Runtime.InteropServices.RuntimeInformation v4.3.0` to your project. If possible, also please check if https://stackoverflow.com/questions/44856450/yet-another-system-runtime-interopservices-error thread give any helps. – Leo Liu Jan 01 '18 at 06:20
  • @LeoLiu-MSFT Thanks for the link. that's my exact problem with MongoDb, but the solution didn't work for me – Blendester Jan 03 '18 at 16:16

1 Answers1

5

It might be a bit late, but I ran into similar problem with MongoDB driver (upgraded from 2.5 to 2.7) on one of our legacy build servers with .net 4.6.2. Oddly enough it was working on the local machine when built with Visual Studio. The problem was NuGet itself, and the wrong assembly binding that was added during package updates. We had to manually check the correct assembly versions and overwrite the values in the app.config.

Make sure that you activate detailed logging by adding the following registry key on the target machine: HKLM\Software\Microsoft\Fusion > EnableLog (DWORD) set to 1

Then you can get more verbose info which exact DLL is causing problems.

The following PowerShell command can help finding the correct assembly versions. For instance for InteropServices:

[System.Reflection.Assembly]::LoadFrom("C:\path_to_your_release_folder\System.Runtime.InteropServices.RuntimeInformation.dll").GetName().Version

In our case it was:

Major  Minor  Build  Revision
-----  -----  -----  -------- 
4      0      1      0

In out app.config NuGet wrote 4.0.2.0, so we just changed that to 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>

and automagically all was working again, as expected.

So, the only way to be sure which binding to use is to check the version yourself using the method I've described above.

Nikola
  • 61
  • 1
  • 4
  • Thanks, this worked for me. Other similar posts suggest you include the binding redirect for System.Runtime but removing this but keeping the redirect for InteropServices caused things to work again. – SalieHendricks Oct 26 '18 at 10:49
  • Thanks a lot!!! This powershell line is gold! What is interesting is that it returns different versions for the DLL on different machines building from the same code. On my local machine I got 4.0.0, while build produced by CI shows 4.0.2. Had to adjust bindingRedirect accordingly – Xantrul Dec 15 '20 at 21:49