我将一个站点从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-appGlobal.asax.cs:125
StatusBoard.Web.MvcApplication.Application_Start() in C:path-to-appGlobal.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
)。
这只是 WebAPI RC 的一个错误吗?有什么方法可以解决这个问题吗?还是我陷入了DLL/Nuget地狱(如果是这样,我该如何自拔)?
请确保包含正确的 nuget 包 (RC!),并在生成包的计算机上安装新的 mvc4rc。
依赖解析已在 RC 中完全重写。最好是卸载测试版 DLL,然后您的问题很可能会消失。
只需卸载Windows的"卸载程序"中标记为"(捆绑)"的那个。