【发布时间】:2013-10-19 18:52:35
【问题描述】:
在我的 Visual Studio 2013 RC 项目中,我收到了这个错误消息:
"定义了类型'System.Net.Http.Formatting.MediaTypeFormatter' 在未引用的程序集中。您必须添加对 程序集'System.Net.Http.Formatting,版本=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
IOW,通过选择工具 > 库包管理器 > 包管理器控制台,然后输入:
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
...它现在可以按预期编译、运行和工作,但这显然是“不是首选方法”
【问题讨论】:
-
你知道这个问题已经有四年了,对吧?
-
“可能重复”是一种清理方法 - 关闭类似问题并保留最佳答案。日期不是必需的。见meta.stackexchange.com/questions/147643/…如果你同意它需要澄清,请投票meta.stackexchange.com/questions/281980/…
标签: .net-assembly visual-studio-debugging visual-studio-2013 system.net mediatypeformatter