C# Asp.NET MVC 4 WebApi升级-RC到4.0.30506.0
我遇到了一个问题,当第一个生产版本Asp.NET WebApi推出时,许多其他人似乎都遇到了这个问题,人们正在从发布候选版本升级到它 虽然我现在对情况有了更好的了解,并且认为我已经缩小了问题的范围,但我已经花了一天的时间尝试了我在网络上找到的每一个解决方案,但运气不佳 具体而言,我的应用程序(无论是部署到本地IIS服务器还是在开发服务器中运行)似乎正在使用较旧的System.Web.Http程序集 应用程序_Start()方法的第二行失败,出现异常C# Asp.NET MVC 4 WebApi升级-RC到4.0.30506.0,c#,asp.net,.net,iis,asp.net-web-api,C#,Asp.net,.net,Iis,Asp.net Web Api,我遇到了一个问题,当第一个生产版本Asp.NET WebApi推出时,许多其他人似乎都遇到了这个问题,人们正在从发布候选版本升级到它 虽然我现在对情况有了更好的了解,并且认为我已经缩小了问题的范围,但我已经花了一天的时间尝试了我在网络上找到的每一个解决方案,但运气不佳 具体而言,我的应用程序(无论是部署到本地IIS服务器还是在开发服务器中运行)似乎正在使用较旧的System.Web.Http程序集 应用程序_Start()方法的第二行失败,出现异常 protected void Applicat
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
**WebApiConfig.Register(GlobalConfiguration.Configuration);**
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
从包含的模板WebApiConfig.cs文件/类调用Register方法:
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
其中,调用config.Routes.MapHttpRoute()会导致以下异常:
Method not found: 'System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()'.
Server stack trace:
at System.Web.Http.GlobalConfiguration.<.cctor>b__0()
at System.Lazy`1.CreateValue()
Exception rethrown at [0]:
at System.Web.Http.GlobalConfiguration.<.cctor>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at System.Web.Http.GlobalConfiguration.get_Configuration()
at MvcApplication2.WebApiApplication.Application_Start()
in C:\Projects\TestArea\ASP_MVC\4\MvcApplication2\Global.asax.cs:line 21
未找到方法:“System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()”。
服务器堆栈跟踪:
在System.Web.Http.GlobalConfiguration.b_uu0()上
在System.Lazy`1.CreateValue()处
在[0]处重试异常:
在System.Web.Http.GlobalConfiguration.b_uu0()上
在System.Lazy`1.CreateValue()处
在System.Lazy`1.LazyInitValue()处
在System.Lazy`1.get_Value()
在System.Web.Http.GlobalConfiguration.get_Configuration()中
在mvcapapplication2.WebApiApplication.Application_Start()中
在C:\Projects\testrea\ASP\u MVC\4\mvcapapplication2\Global.asax.cs中:第21行
到目前为止,我所做的事情是:
- 重新安装所有版本的.NET
- 从GAC中删除System.Web.Http
- 确保项目引用指向WebApi目录,而不是操作系统的.NET程序集
- 确保将项目引用设置为“复制本地”
- 已从c:\windows\system32\inetsrv\和c:\inetpub中删除IIS的临时文件
- 运行了c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet\u regiis.exe
- 通过NuGet更新了所有与WebApi相关的软件包
- 已停止并启动IIS和站点
- 重新启动
我只是不知道还能做什么。非常感谢您的帮助。谢谢。既然萨默斯自己找到了答案,我就把它作为正式答案贴在这里 我相信解决方案是检查输出窗口中加载的各种DLL,查找仍在使用RC版本的版本,找到它们的位置并删除它们
在他的情况下,这是因为RC显然向GAC添加了一些DLL(MVC4的发行版不再这样做,因为它们都是bin部署的)。您是否检查过项目是否引用System.Web.Http.WebHost.DLL和版本4?有什么例外?是的,我验证了所有引用。对不起,我在帖子中添加了:找不到方法:“System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()”。是否使用依赖项注入?