0

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?

Teoman shipahi
  • 47,454
  • 15
  • 134
  • 158
  • You'd better ask MSBuild to give you diagnostics. Without that it is not clear who copied the old version around. – Lex Li Sep 18 '16 at 00:30
  • How do you set your PCL project Targets? I create a sample PCL project targets to .NET 4.5, Windows 8, Windows Phone 8 and Xamarin Android. After I install Microsoft HTTP Client Libraries 2.2.29, the System.Net.Http.Primitives.dll version is 1.5.9. And I don't set bindingRedirect in my WebApp, both of my Xamrin app and Web App could build successful. Could you share a sample project here to reproduce this issue in my side? – Weiwei Sep 19 '16 at 04:28
  • @Wendy please see here https://github.com/reyou/CrossLibraryReference download this project and first build web app and check bin folder then build class library 2 and check bin folder again. Try with VS 2015 community edition if possible please. Here is my experience: https://github.com/reyou/CrossLibraryReference/tree/master/debugImages this time it happened over "System.Net.Http.Extensions.dll" – Teoman shipahi Sep 19 '16 at 14:57
  • For your sample solution, it works fine in my side. Both of the Http.Extensions.dll and Http.Primitives.dll are use the high version in Web project and ClassLibrary2 project. I build the Web app first, and then reference the ClassLibrary2 in Web app and build again. The dll version are the same. Is there something wrong with my steps? And I also don't find the node in your Web.config file. Please check your sample solution, whether there has anything missing. – Weiwei Sep 20 '16 at 02:09
  • @Wendy I will try to make video recording for steps I am taking. Simply what I will do, clone git repo, open with vs 2015 CE, build web app, check web/bin folder for "System.Net.xxx" reference versions. Then build Class Library 2 and check again in web/bin folder for "System.Net.xxx" reference versions. – Teoman shipahi Sep 20 '16 at 13:50
  • I have reproduce the System.Net.XXX version issue in my side, but I don't get the error message that in Web app. – Weiwei Sep 21 '16 at 02:18
  • Yes because I did not include reference redirection in web.config. If you do that, it will not find target library and fail. Anyway, regardless of that, why Class Library 2 would override .dll in Web Folder? Is this a bug? – Teoman shipahi Sep 21 '16 at 02:30
  • Have you tried with https://www.nuget.org/packages/Microsoft.Bcl.Build/? Mode description for it: http://stackoverflow.com/questions/22824804/what-does-the-microsoft-bcl-build-nuget-package-do – Eddie Chen - MSFT Sep 26 '16 at 08:57

1 Answers1

0

I know this is not a proven solution but, I had to remove projects from solution one by one and add back in. Then I re-mapped project dependencies by right clicking on projects and choosing dependencies on them. It seems like working right now. It might be a problem with VS build order when more than 3 projects are cross referencing each other.

Teoman shipahi
  • 47,454
  • 15
  • 134
  • 158