转到Web API RC,Get:找不到方法:'System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()'

时间:2012-06-12 10:17:37

标签: asp.net-mvc-4 asp.net-web-api

我将网站从WebAPI Beta移至WebAPI RC,现在加载网站时出现错误:Method not found: 'System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()'.

第一次尝试注册我的AutoFacWebApiDependencyResolver时出现错误(按照说明here):

var resolver = new AutofacWebApiDependencyResolver(IoCManager.Container);
GlobalConfiguration.Configuration.DependencyResolver = resolver;

堆栈跟踪显示以下内容:

[MissingMethodException: Method not found: 'System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()'.]
   System.Web.Http.GlobalConfiguration.<.cctor>b__0() +0
   System.Lazy`1.CreateValue() +12775823
   System.Lazy`1.LazyInitValue() +355
   StatusBoard.Web.MvcApplication.RegisterDependencyInjection() in C:\path-tp-app\Global.asax.cs:125
   StatusBoard.Web.MvcApplication.Application_Start() in C:\path-to-app\Global.asax.cs:75

基于此,似乎在静态GlobalConfiguration类的初始化期间发生了错误。当我深入研究该类的源代码时,我看到以下内容:

private static Lazy<HttpConfiguration> _configuration = new Lazy<HttpConfiguration>((Func<HttpConfiguration>) (() =>
{
  local_0 = new HttpConfiguration((HttpRouteCollection) new HostedHttpRouteCollection(RouteTable.Routes));
  local_0.get_ServiceResolver().SetService(typeof (IBuildManager), (object) new WebHostBuildManager());
  return local_0;
}));
private static Lazy<HttpControllerDispatcher> _dispatcher = new Lazy<HttpControllerDispatcher>((Func<HttpControllerDispatcher>) (() => new HttpControllerDispatcher(GlobalConfiguration._configuration.Value)));

public static HttpConfiguration Configuration
{
  get
  {
    return GlobalConfiguration._configuration.Value;
  }
}

这里的第四行似乎是问题 - 它试图调用HttpConfiguration类中不再存在的get_ServiceResolver()方法(可能应该是DependncyResolver)。

这只是RC for WebAPI的一个错误吗?有什么方法可以解决这个问题吗?或者我陷入了一些DLL / Nuget地狱(如果是这样,我怎么能自拔)?

2 个答案:

答案 0 :(得分:1)

确保包含正确的nuget包(RC!)并在构建包的机器上安装新的mvc4rc。

答案 1 :(得分:0)

依赖性解决方案已在RC中完全重写。最好是卸载测试版DLL,然后你的问题很可能会消失。

只需在Windows“卸载程序”中卸载标记为“(bundle)”的文件即可。