从哪里引用缺少的程序集(System.Net.Http.Formatting)?

B. *_*non 48 system.net .net-assembly visual-studio-debugging mediatypeformatter visual-studio-2013

在我的Visual Studio 2013 RC项目中,我得到了这个错误信息:

" 类型'System.Net.Http.Formatting.MediaTypeFormatter'是在未引用的程序集中定义的.您必须添加对程序集'System.Net.Http.Formatting,Version = 4.0.0.0,Culture = neutral, PublicKeyToken = 31bf3856ad364e35' "

...在"var response = "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;
}
Run Code Online (Sandbox Code Playgroud)

在我的硬盘中搜索所需的程序集("System.Net.Http.Formatting"),它向我显示了它存在的几个位置,但它们都在现有项目中,如下所示:

在此输入图像描述

当然还有另一个位置,可以从中引用System.Net.Http.Formatting.dll!但是哪里?

UPDATE

试着按照这里的线索:http://www.nuget.org/packages/System.Net.Http.Formatting

IOW,选择工具>库包管理器>包管理器控制台,然后输入:

Install-Package System.Net.Http.Formatting -Version 4.0.20710
Run Code Online (Sandbox Code Playgroud)

......我看到潘普洛纳(不是饮料)的红牛在我身上肆虐:

在此输入图像描述

更新2

我从这里添加了System.Net.Http.Formatting.dll:

C:\Users\clay\My Documents\Visual Studio 2013\Projects\MvcApplication1\MvcApplication1\bin
Run Code Online (Sandbox Code Playgroud)

......它现在编译并运行并按预期工作,但这显然是"不是首选的方法"

小智 77

我有同样的问题.我使用的是Microsoft Asp Net WebApi Client 4.0.20710,它对我有用.

在工具>库包管理器>包管理器控制台中键入以下命令:

Install-Package Microsoft.AspNet.WebApi.Client -Version 4.0.20710
Run Code Online (Sandbox Code Playgroud)


Cam*_*ron 41

加上Luiz在上面回答的内容.

System.Net.Http.Formatting是一个库,用于媒体类型格式化.例如:http: //msdn.microsoft.com/en-us/library/system.net.http.formatting.jsonmediatypeformatter(v=vs.118).aspx

在引用它时,当我尝试时,我希望在我的项目中添加一个引用,并查看Reference Manager中的Assemblies/Framework文件夹.

它实际上位于Reference Manager的Assemblies/Extensions文件夹中

  • 我在Reference Manager的Assemblies/Extensions文件夹中没有System.Net.Http.Formatting.dll. (8认同)
  • 这个答案要比公认的正确答案好得多.你不应该使用nuget来引用它. (7认同)
  • 同样在这里 - 我没有在Assemblies/Extensions中看到它. (3认同)

fel*_*Dev 9

如果您在尝试安装System.Net.Http.Formatting -Version 4.0.20710时遇到错误,请尝试以下方法:

Install-Package WebApiDoodle.Net.Http.Formatting -Pre
Run Code Online (Sandbox Code Playgroud)

我刚刚在NuGet上找到:https://www.nuget.org/packages/WebApiDoodle.Net.Http.Formatting/3.0.0-pre01


小智 5

右键单击项目,然后单击添加引用选项,然后去扩展组件选项卡,然后选择System.Net.Http.Formatting。 如果这里没有,您必须手动添加 prgramme 文件-> Microsoft ASP.NET