我将一个站点从 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 地狱(如果是这样,我该如何自拔)?