2

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

第一次尝试注册我的错误时发生AutoFacWebApiDependencyResolver(根据此处的说明):

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;
  }
}

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

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

4

2 回答 2

1

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

于 2012-06-12T11:17:22.260 回答
0

依赖关系解析已在 RC 中完全重写。最好是卸载 beta DLL,然后您的问题很可能会消失。

只需在 Windows 的“卸载程序”中卸载标记为“(捆绑)”的那个。

于 2012-06-12T10:30:40.647 回答