I found myself in a weird situation with the System.Runtime.InteropServices.RuntimeInformation NuGet package.
My application is targeting .NET 4.6.2(had to downgrade to 4.6.2 from 4.8 since this is a client application and some of the clients didn't have 4.8 installed) and when I try to run it on a machine where the highest .NET version available is 4.6.2 I get the following error:
IO.FileLoadException: Could not load file or assembly ‘System.Runtime.InteropSer
vices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5
f7f11d50a3a’ or one of its dependencies. The located assembly’s manifest definit
ion does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: ‘System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’
at Topshelf.HostConfigurators.HostConfiguratorImpl.CreateHost()
at Topshelf.HostFactory.New(Action`1 configureCallback)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\M
icrosoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure lo
gging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus
ion!EnableLog].
Topshelf.HostFactory Error: 0 : The service terminated abnormally, System.IO.Fil
eLoadException: Could not load file or assembly ‘System.Runtime.InteropServices.
RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d
50a3a’ or one of its dependencies. The located assembly’s manifest definition do
es not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: ‘System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’
at Topshelf.HostConfigurators.HostConfiguratorImpl.CreateHost()
at Topshelf.HostFactory.New(Action`1 configureCallback)
at Topshelf.HostFactory.Run(Action`1 configureCallback)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\M
icrosoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure lo
gging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fus
ion!EnableLog].
I used Fusion++ on the same machine to get the assembly binding failure and the result I got is:
=== Pre-bind state information ===
LOG: DisplayName = System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/VS/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = VS.Service.exe
Calling assembly : Topshelf, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b800c4cfcdeea87b.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Program Files (x86)\VS\VS.Service.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Runtime.InteropServices.RuntimeInformation, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/VS/System.Runtime.InteropServices.RuntimeInformation.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Program Files (x86)\VS\System.Runtime.InteropServices.RuntimeInformation.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
All that being said, I don't know what I'm supposed to do in this situation. The packages I have installed that have a dependency on System.Runtime.InteropServices.RuntimeInformation are TopShelf, CliWrap, and NETStandard.Library
When I check the reference in my IDE it shows that the assembly version is 4.0.1.0, but in the output folder the assembly version of the DLL is 4.0.2.0
Any help would be highly appreciated. Thanks.
If the DLL is present in the output folder, but with a different version than expected by the dependent packages, you can add a file named "PackageName.dll.config" (for each dependent package) with this content:
Put the files in the root folder of the project and set their "Build Action" to "Content" and "Copy to Output Directory" to "Copy if newer". That will point to the dependent packages that they can accept the existing version of the DLL.
(P.S.: I'm facing a similar error, but in my case, despite the project is explicitly referencing the System.Runtime.InteropServices.RuntimeInformation DLL, it is not being copied to output folder when the project is built )