I have an asp.net core 2.0 project with a net47 class library. The library uses the latest version of the Microsoft.AspNet.WebApi.Client package.
When I copy and paste this dll into a completely different solution with a Webforms project and DataLayer class library both targeting .NET Framework 7.1.
The DataLayer in the Webforms solution also has Microsoft.AspNet.WebApi.Client installed, but adds the following:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.2" newVersion="4.1.1.2" />
</dependentAssembly>
I end up with the following error:
Could not load file or assembly 'System.Net.Http, Version=4.2.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)
With a lucky guess I was able to resolve the issue by doing the following:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.1.1.2" />
</dependentAssembly>
How come I have to redirect to use version 4.1.1.2. Why can't it just work with version 4.2.0.0? And why is it requesting 4.2.0.0 in the first place? I am assuming the 4.2.0.0 is coming from the ASP.NET Core net47 class library reference.