在我的Visual Studio 2013 RC项目中,我收到了以下错误消息:
"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'"
...出现在控制器的"var response = "
代码行:
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;
}
搜索我的硬盘以获取所需的程序集(“System.Net.Http.Formatting”),它显示了几个存在的位置,但它们都在现有项目中,如下所示:
肯定还有另一个位置可以引用System.Net.Http.Formatting.dll!但是在哪里呢?更新
尝试按照这里的提示:http://www.nuget.org/packages/System.Net.Http.Formatting 即通过选择工具 > 库包管理器 > 包管理器控制台,并输入:
Install-Package System.Net.Http.Formatting -Version 4.0.20710
我看到了帕姆普洛纳的红牛(不是饮料),它们狂野地向我奔来:
更新 2
我从这里添加了 System.Net.Http.Formatting.dll:
C:\Users\clay\My Documents\Visual Studio 2013\Projects\MvcApplication1\MvcApplication1\bin
...现在它可以编译、运行并按预期工作,但这显然“不是首选方法”