System.Net.Http could not be resolved in the currently targeted framework .NET 4.0
Asked Answered
L

2

15

Got a nasty error after moving a solution from Visual Studio 2010 to 2012. Build is fine and everything works perfect localhost. I have one new MVC4 project that requires .NET 4.5 so I installed the 4.5 framework on the build server. The build is good but MSBuild is failing to copy DotNetOpenAuth.Core.dll from its package location to the Bin dir. The issue is because, though the particular project targets the 4.0 framework, I believe MSBuild is checking the dependency against .NET 4.5 framework System.Net.Http assembly as part of its CoreBuild.

warning code="MSB3268" The primary reference \packages\DotNetOpenAuth.Core.4.3.0.13117\lib\net40-full\DotNetOpenAuth.Core.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "c:\cc\kazork\code\trunk\src\packages\DotNetOpenAuth.Core.4.3.0.13117\lib\net40-full\DotNetOpenAuth.Core.dll" or retarget your application to a framework version which contains "System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Here is my package config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="ChardinJs" version="1.0.3" targetFramework="net40" />
  <package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" />
  <package id="DotNetOpenAuth.AspNet" version="4.3.0.13117" targetFramework="net40" />
  <package id="DotNetOpenAuth.Core" version="4.3.0.13117" targetFramework="net40" />
  <package id="DotNetOpenAuth.OAuth.Consumer" version="4.3.0.13117" targetFramework="net40" />
  <package id="DotNetOpenAuth.OAuth.Core" version="4.3.0.13117" targetFramework="net40" />
  <package id="DotNetOpenAuth.OpenId.Core" version="4.3.0.13117" targetFramework="net40" />
  <package id="DotNetOpenAuth.OpenId.RelyingParty" version="4.3.0.13117" targetFramework="net40" />
  <package id="EntityFramework" version="5.0.0" targetFramework="net40" />
  <package id="flexigrid" version="1.1.0" targetFramework="net40" />
  <package id="jQuery" version="1.9.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.FriendlyUrls.Core" version="1.0.0" targetFramework="net40" />
  <package id="Microsoft.AspNet.Membership.OpenAuth" version="1.0.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.Core" version="1.1.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.JS" version="1.1.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.Owin" version="1.1.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.SignalR.SystemWeb" version="1.1.1" targetFramework="net40" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.0.0" targetFramework="net40" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="1.0.1" targetFramework="net40" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
  <package id="Newtonsoft.Json" version="5.0.5" targetFramework="net40" />
  <package id="Owin" version="1.0" targetFramework="net40" />
  <package id="PayPalCoreSDK" version="1.1.1" targetFramework="net40" />
  <package id="PayPalMerchantSDK" version="2.3.98" targetFramework="net40" />
  <package id="Select2.js" version="3.3.2" targetFramework="net40" />
  <package id="toastr" version="1.2.2" targetFramework="net40" />
  <package id="Twitter.Bootstrap" version="2.3.2" targetFramework="net40" />
  <package id="WebGrease" version="1.3.0" targetFramework="net40" />
</packages>

I have System.Net.Http referenced and it is copied to the bin. The project in question is targeting the 4.0 framework. My version System.Net.Http is for the 4.0 framework.

Long answered 26/5, 2013 at 4:14 Comment(0)
L
30

So even though I was copying System.Net.Http .NET 4.0 via the Nuget package that is added when installed the DotNetOpenAuth packages, MsBuild on my build server was checking the DotNetOpenAuth.Core dependency and checking against .NET assemblies installed on the machine not what was being copied to the Bin. In my case:

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0

And there was no System.Net.Http assembly in my

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0

directory so I believe MsBuild attempted to look in the newly installed .NET 4.5 assemblies, on my machine..\Assemblies\Microsoft\Framework.NETFramework\v4.5 where there is a System.Net.Http.dll and that is why, instead of getting an outright error that System.Net.Http.dll for .NET 4.0 targets does not exist, I got a warning about DotNetOpenAuth.Core.dll's dependency on System.Net.Http, which can be found but is not for the 4.0 framework as the project was targeting.

I simply copied System.Net.Http .NET 4.0 DLL from the package to

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0

on my build server and MsBuild was able to compare to the correct version System.Net.Htpp for 4.0 .NET framework dependency check.

Long answered 26/5, 2013 at 19:19 Comment(7)
Did you find the real problem to this? I really think that is weird that the dll that you have in your package folder is not used. I have exactly the same problem, but it didn't help to copy the system.net.http file.Consanguineous
My builds quit working after I downgraded from .net 4.5 to 4.0. In my case System.Net.Http and System.Web.Http where both missing from the .NETFramework\v4.0 folder on the build server. Thanks for sharing your resolution!Finely
No problem!! Very glad to here it helped, it was quite a painful bug!Long
What a painful bug, man. I was freaking punching my walls and recreating projects like a mad man trying to figure what the crack was going on. I also copied System.Net.Http.WebRequest.dll. Thanks! It's working like a charm, and without freaking warning sign.Bandmaster
Glad it helped, yes it was quite a nasty bugLong
Where did you downloaded the file ? ThxWiburg
@Wiburg in my answer I state "I simply copied System.Net.Http .NET 4.0 from the package"Long
I
1

If this fails, you may also need to apply the .Net v4.5.1 dev pack as this supports multiple targeting. I had 4.5.1 installed and the assemblies copied and still had this error. Installing the dev pack from http://www.microsoft.com/en-us/download/details.aspx?id=40772 fixed this issue and now builds under server 2012 r2.

Incunabula answered 18/12, 2014 at 19:57 Comment(1)
tried this, didn't work after a full wipe of the workspaceThorstein

© 2022 - 2024 — McMap. All rights reserved.