I am using Microsoft HTTP Client Libraries 2.2.29 for my WebApp and PCL.
Here is the link: https://www.nuget.org/packages/Microsoft.Net.Http/
PCL is using System.Net.Http.Primitives.dll version 1.7.29 because of compatibility.
MVC project is pulling System.Net.Http.Primitives.dll version 4.2.29 because it is compatible with 4.5 framework. It also has dependency to my PCL.
If I only build my WebApp it works fine, because it pulls 4.2.29 version. But if I build another project which depends on my PCL (for example Xamarin APP), it throws 1.7.29 version into web/bin folder and I receive following error on Web Project.
[FileLoadException: Could not load file or assembly 'System.Net.Http.Primitives, Version=4.2.29.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)]
System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +234
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection) +108
System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +25 System.Reflection.Assembly.Load(String assemblyString) +34
System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +49
I have following config at my web.config:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.29.0" newVersion="4.2.29.0" />
</dependentAssembly>
PCL packages.config
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="portable45-net45+win8+wp8+wpa81" />
WebAPP packages.config
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net451" />
I can remove web.config configuration to make it work with version 1.7.29. But I do not want to do this, there I would like to use latest compatible version of this library of each project.
Why VS 2015 community edition/nuget would place non-compatible/lower version of library into web/bin folder while I am building non-related project?
How can I fix this issue?