【问题标题】:ASP.NET Web API conflict after installing VS 2012 Ultimate安装 VS 2012 Ultimate 后 ASP.NET Web API 冲突
【发布时间】:2012-08-25 11:09:32
【问题描述】:

我不久前安装了 asp.net mvc-4 beta 来托管我们的 api。在我刚刚在我的机器上安装了 vs2012 Ultimate 之前它运行良好。该项目既不在 vs2010 也不在 vs2012 中编译。我能做些什么来解决这个冲突。此外,我在我的服务器上部署了 asp.net web api 程序集。我必须做什么才能在服务器上运行最新版本(一旦前面的问题得到解决)?

编辑:
我在 vs2012 中打开时的编译错误是

'System.Net.Http.HttpRequestMessage' does not contain a definition for 'GetUserPrincipal' and no extension method 'GetUserPrincipal'...

'System.Web.Http.Hosting.HttpPropertyKeys' does not contain a definition for 'UserPrincipalKey'

另一方面,在 vs 2010 中,它拒绝接受 DelegatingHandler 等类型。一些错误如下。

The type or namespace name 'DelegatingHandler' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'HttpResponseMessage' could not be found (are you missing a using directive or an assembly reference?)

我也安装了最新版本的 asp.net mvc 4,它显示的版本是 4.0.20713.0。以前,我使用 nuget 添加了 web-api beta。我已将它们全部删除并从 nuget 安装了最新版本的 web-api。我不知道可能是什么问题。一件事,我不明白:为什么我需要单独安装 web-api 程序集,因为它们应该是 mvc 框架的一部分? 谢谢

【问题讨论】:

  • 编译器错误会很有用。要更新您的 web api 箱,只需使用 nuget 并将您当前的箱替换为 RTM 版本或夜间构建。
  • 第一个错误是找不到类型或命名空间FormatterContextHttpRepsonseMessageHttpRequestMessage 也是如此
  • 我的编译没有问题,但 Intellisense 一直强调它说它不存在。不知道是怎么回事。

标签: asp.net-mvc-4 asp.net-web-api visual-studio-2012


【解决方案1】:

使用 System.ServiceModel.Channels 添加;到你的文件。根据THIS,HttpRequestMessage 的扩展方法存在于这个命名空间中。

【讨论】:

  • 通过在using System.ServiceModel.Channels; 周围加上反引号,您可以标记代码片段。
【解决方案2】:

添加

using System.Net.Http;

您可能已经有了参考,所以只需添加扩展方法的 using。
否则添加同名的程序集。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-19
    • 1970-01-01
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-16
    相关资源
    最近更新 更多