59

In my Visual Studio 2013 RC project, I'm getting this err msg:

"The type 'System.Net.Http.Formatting.MediaTypeFormatter' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'"

...on the "var response = " line of code in a Controller:

public HttpResponseMessage PostDelivery(Delivery delivery)
{
    delivery = repository.Add(delivery);
    var response = Request.CreateResponse<Delivery>(HttpStatusCode.Created, delivery);

    string uri = Url.Link("DefaultApi", new { id = delivery.Id });
    response.Headers.Location = new Uri(uri);
    return response;
}

Searching my hard drive for the required assembly ("System.Net.Http.Formatting"), it shows me several locations where it exists, but they are all within existing projects, as is seen here:

enter image description here

Surely there is another location from which System.Net.Http.Formatting.dll can be referenced! But where?

UPDATE

Trying to follow the clue here: http://www.nuget.org/packages/System.Net.Http.Formatting

IOW, by selecting Tools > Library Package Manager > Package Manager Console, and entering:

Install-Package System.Net.Http.Formatting -Version 4.0.20710

...I see the red bulls of Pamplona (not the beverage) descending wild-eyed upon me:

enter image description here

UPDATE 2

I added the System.Net.Http.Formatting.dll from here:

C:\Users\clay\My Documents\Visual Studio 2013\Projects\MvcApplication1\MvcApplication1\bin

...and it now compiles and runs and works as expected, but that is obviously "not the preferred method"

Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
  • Possible duplicate of [Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies. The system cannot find the path specified](https://stackoverflow.com/questions/22403650/could-not-load-file-or-assembly-system-net-http-formatting-or-one-of-its-depen) – Michael Freidgeim Oct 12 '17 at 04:57
  • 1
    You do realize this question is four years old, right? – B. Clay Shannon-B. Crow Raven Oct 13 '17 at 13:40
  • "Possible duplicate" is a way to clean-up - to close similar questions and keep one with the best answers. The date is not essential. See http://meta.stackexchange.com/questions/147643/should-i-vote-to-close-a-duplicate-question-even-though-its-much-newer-and-ha If you agree that it requires clarification please vote on http://meta.stackexchange.com/questions/281980/add-clarification-link-to-possible-duplicate-automated-comment – Michael Freidgeim Oct 13 '17 at 21:32

6 Answers6

101

I had the same problem. I used Microsoft Asp Net WebApi Client 4.0.20710 and it worked for me.

Type the following command into Tools > Library Package Manager > Package Manager Console:

Install-Package Microsoft.AspNet.WebApi.Client -Version 4.0.20710
Tohid
  • 6,175
  • 7
  • 51
  • 80
TheMightyX2Y
  • 1,473
  • 1
  • 16
  • 24
  • 1
    how to access `Tools > Library Package Manager > Package Manager Console`? – Elyor Aug 14 '15 at 09:18
  • @Elyor share pls – Jean-Paul Oct 26 '17 at 10:55
  • Really MS should have kept the Nuget package around for System.Net.Http.Formatting with a dependency on the Microsoft.AspNet.WebApi.Client package.. but instead they broke that normal usage of Nuget and caused this to generate errors with deployments and compilation getting broken at times with a cryptic error message of a missing assembly... ugh... – Chris Pietschmann Mar 12 '19 at 21:23
  • I fail to see the link between Microsoft.AspNet.WebApi.Client and System.Net.Http.Formatting.MediaTypeFormatter, not clearly explained. – Adrian Nasui Jul 01 '19 at 07:08
  • In VS 2019 I found it under Tools > NuGet Package Manager > Package Manager Console and it the Install-Package string worked – AverageHomosapien Apr 25 '21 at 14:33
43

Adding to what Luiz answered above.

System.Net.Http.Formatting is a library and is used for media type formatting. For example: http://msdn.microsoft.com/en-us/library/system.net.http.formatting.jsonmediatypeformatter(v=vs.118).aspx

When referencing it, when I tried, I was looking to add a reference in my project and was looking in the Assemblies/Framework folder in Reference Manager.

It is actually in the Assemblies/Extensions folder in Reference Manager

Cœur
  • 37,241
  • 25
  • 195
  • 267
Cameron
  • 1,218
  • 2
  • 13
  • 19
  • Cheers, was stumped. Good answer. – CountZero Feb 16 '15 at 17:51
  • This needs to be higher! Worked like a charm! – brianestey Oct 07 '15 at 20:55
  • 9
    This answer is much better than the accepted right answer. You shouldnt need to use nuget to reference this. – bytedev Jan 13 '16 at 09:59
  • 13
    I have not System.Net.Http.Formatting.dll in Assemblies/Extensions folder in Reference Manager. – SerG May 16 '16 at 14:19
  • 5
    Same here - I don't see it in Assemblies/Extensions. – jbyrd May 17 '17 at 15:50
  • Sorry it is not. In one machine the dll was found here "C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies" and it was loading correctly. In the machine where it said it is missing there were just xml files in the same folder (with the same name as dlls) – Blue Clouds Mar 22 '18 at 13:17
9

If you got an error trying to install System.Net.Http.Formatting -Version 4.0.20710, try this one:

Install-Package WebApiDoodle.Net.Http.Formatting -Pre

I just found on NuGet: https://www.nuget.org/packages/WebApiDoodle.Net.Http.Formatting/3.0.0-pre01

felippeDev
  • 91
  • 1
  • 2
6

Right click on project and click Add a reference option, then go to Extensions from Assemblies tab and choose System.Net.Http.Formatting. If it is no in here you have to manually add in prgramme files-> Microsoft ASP.NET

2

One other simple option for resolving this is to right click on references, click 'Manage NuGet References', Browse for 'Microsoft.AspNet.WebApi.Client' and install it or perhaps reinstall it. Review the package information to learn more.

GrayDwarf
  • 2,469
  • 2
  • 20
  • 22
1

I ran into the same problem on vs2022 v16.11.5.
I was fortunate enough to have the project working on one machine but not another. On the suspect machine, under project References, System.Net.Http.Formatting could not be found. Running the visual studio installer app and modifying the vs2022 install to include the ASP.NET and web development package fixed me up.

ASP.NET and Web development Install image