Could not load file or assembly or one of its dependencies.

0

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.

c#
visual-studio
nuget
asked on Stack Overflow Dec 30, 2017 by Blendester

1 Answer

1

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.

answered on Stack Overflow Oct 2, 2018 by Nikola

User contributions licensed under CC BY-SA 3.0