While migrating our Lydia solution from PCL to .NET Standard and upgrading the various projects, my tests started to fail with the following exception:
Could not load file or assembly ‘System.Reactive.Interfaces, Version=18.104.22.168, Culture=neutral, PublicKeyToken=94bc3704cddfc263’ or one of its dependencies. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
My test assembly
Tests.Epsitec.Extensions targets .NET 4.6.2 and references
System.Reactive. It also references project
Epsitec.Extensions which builds
an assembly adhering to .NET Standard 1.3, and which also references the NuGet
System.Reactive v3.1.1, Visual Studio 2015 adds following
assemblies to both projects:
- System.Reactive.Core, v3.1.1
- System.Reactive.Interfaces, v3.1.1
When the test is executed, .NET tries to load assembly
but this fails. Here is the detailed information (edited for clarity):
- DisplayName: System.Reactive.Interfaces, Version=22.214.171.124, PublicKeyToken=94bc3704cddfc263
- Appbase: file:///S:/git/rnd/lydia-dev/lydia/Tests.Epsitec.Extensions/bin/Debug
- Calling assembly: Epsitec.Extensions, Version=126.96.36.199, PublicKeyToken=…
- Using application configuration file: Tests.Epsitec.Extensions.dll.config
- Post-policy reference: System.Reactive.Interfaces, Version=188.8.131.52 …
- Comparing the assembly name resulted in the mismatch: Build Number
- Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
So what’s going on here?
When the test project starts, it loads
3.0.1000.0) found in packages/System.Reactive.Interfaces.3.1.1/lib/net45.
When .NET tries to load
Epsitec.Extensions, no matching
can be located. Indeed, the assembly was compiled as .NET Standard 1.3 and thus refers
to another version (184.108.40.206) found in packages/System.Reactive.Interfaces.3.1.1/lib/netstandard1.0.
Configure an assembly binding redirection
The solution is to add this
<dependentAssembly> entry in the test project’s app.config
<dependentAssembly> <assemblyIdentity name="System.Reactive.Interfaces" publicKeyToken="94bc3704cddfc263" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.1000.0" /> </dependentAssembly>
This tells the loader to map all versions up to 3.0.3000.0 to the one which gets loaded with the test project (3.0.1000.0). With this in place, everything works fine again. See MSDN for a detailed explanation.
System.Reactive.Interfaces was not included in the redirects when
I added the NuGet package System.Reactive. Yet, there was a redirect for the
I don’t know the reason for this. But with the current version of Visual Studio 2015 Update 3, the error is systematic.