C#-无法调用HttpConfiguration扩展方法 [英] C# - Cannot call a HttpConfiguration Extension Methods

查看:594
本文介绍了C#-无法调用HttpConfiguration扩展方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法调用HttpConfiguration扩展方法:

using System.Configuration;
using System.Web.Http;
...
      var config = new HttpConfiguration();
      config.MapHttpAttributeRoutes();  // <-- error

错误:"System.Web.Http.HttpConfiguration"不包含 MapHttpAttributeRoutes的定义,没有扩展方法 'MapHttpAttributeRoutes'接受类型的第一个参数 可以找到"System.Web.Http.HttpConfiguration"(您是否缺少 使用指令还是程序集引用?)

Error: 'System.Web.Http.HttpConfiguration' does not contain a definition for 'MapHttpAttributeRoutes' and no extension method 'MapHttpAttributeRoutes' accepting a first argument of type 'System.Web.Http.HttpConfiguration' could be found (are you missing a using directive or an assembly reference?)

我同时尝试了System.Web.Http版本4和5,以及".NET Framework 4.5.2"和".NET Framework 4".

I tried both with System.Web.Http version 4 and 5, and with ".NET Framework 4.5.2" and ".NET Framework 4".

我想念什么?

推荐答案

确保在执行该代码的项目中具有对Assembly System.Web.Http.dll, v5.2.3.0的引用. HttpConfigurationExtensions.MapHttpAttributeRoutes已添加到ASP.NET Web API 2.2中,它需要上述版本的程序集.

Make sure you have a reference to Assembly System.Web.Http.dll, v5.2.3.0 in your project where that code is being executed. HttpConfigurationExtensions.MapHttpAttributeRoutes was added to ASP.NET Web API 2.2 which requires the above mentioned version of the assembly.

这篇关于C#-无法调用HttpConfiguration扩展方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆