我正在使用MVC4构建网站。我甚至无法开始我有一个奇怪的错误。这是我的代码:HttpConfiguration缺少程序集
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
namespace MyProject
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
}
的错误消息:程序集“HttpConfiguration”在命名空间中不存在的类型或名称“System.Web.Http”(是否缺少using指令或程序集引用?)
它也不会承认只读字段RouteParameter。它发生在我身上,它可能与版本有关,我的System.Web dll版本是4.0.0.0。
另一附加一条信息是,当I型“使用的System.Web。”,智能感知识别.Http DLL
然而,在代码,它不识别任何它的参数。
的'HttpConfiguration'类是'System.Web.Http'库。 – Jay
是的,代码显示它使用System.Web.Http。但它不识别HttpConfiguration(也不知道它是否识别RouteParameter) – Soph
'System.Web'程序集包含System.Web.Http命名空间中的类,这就是为什么你在那里看不到错误,但是'HttpConfiguration'类在'System.Web.Http'程序集中,而不是'System.Web'。你可以验证你有两个程序集引用? – Jay