Background

Today I was about to deploy an app to the server when I realized I had been building against .NET 4.5 while the server only had .NET 4.0 on it.  

Not a big deal, right?  I just needed to change the “Target Framework” in the project properties.  So I did, and it wouldn’t build.  Turns out I had some NuGet references that were targetting .NET 4.5.

Again, no big deal.  Remove EF 5.0 and add EF 4.4 (which is conspicuously named EF 5).  My build succeeds and gets deployed to the development server.

But it won’t run.  I dig around and find other NuGet references (specifically, Newtonsoft.Json) that also are targetting the wrong framework version.  I uninstall and re-install it (and Web API Client and HttpClient).

The Error

But at this point, my solution doesn’t even build.  I kept getting an error message:

‘System.Net.Http.HttpContent’ does not contain a definition for ‘ReadAsAsync’ and no extension method ‘ReadAsAsync’ accepting a first argument of type ‘System.Net.Http.HttpContent’ could be found (are you missing a using directive or an assembly reference?)

But I have a reference to System.Net.Http.Formatting where that extension method is defined.  In fact, when I use Visual Studio’s Go To Definition function, it takes me right to the definition.  At this point I’m perplexed.  So I do what any other developer would do.  Repeatedly remove and re-add the NuGet references, trying to figure out why it won’t build.

The Fix

All in all, I probably wasted almost three hours on this today before I found the fix.  I had to comment out the line of code that had errors and build the solution.  Once I had a solution that successfully built, I uncommented the line and the solution built successfully.

I don’t know why this fixed the issue.  I could spend more time trying to figure out why, but frankly, at this point, I don’t care.  I’m just glad I got my app deployed to the dev and test servers today and that I finally get to work on the project I planned to start last week.