9

我之前有一个 MVC4 应用程序,我已经更新了 Autofac 的版本,一切正常,现在我有这个奇怪的异常。

请帮忙!?

Method not found: 'Autofac.Builder.IRegistrationBuilder`3<!0,!1,!2> Autofac.Builder.IRegistrationBuilder`3.InstancePerMatchingLifetimeScope(System.Object)'.



Line 22:             var builder = new ContainerBuilder();
Line 23:             builder.RegisterFilterProvider();
Line 24:             builder.Register(x => new AuthorizationService()).As<IAuthService>().InstancePerHttpRequest();
Line 25:             builder.Register(x => new HeaderRepository()).As<IUIHeaderRepository>().InstancePerHttpRequest();
Line 26:             builder.Register(x => new PageBuilder()).As<IUPageBuilder>().InstancePerHttpRequest();

堆栈跟踪:

 [MissingMethodException: Method not found: 'Autofac.Builder.IRegistrationBuilder`3<!0,!1,!2> Autofac.Builder.IRegistrationBuilder`3.InstancePerMatchingLifetimeScope(System.Object)'.]
       Autofac.Integration.Mvc.RegistrationExtensions.InstancePerHttpRequest(IRegistrationBuilder`3 registration) +0
       Application.UI.Web.Services.HttpDependencyInjectionResolver.RegisterDependencies() in c:\Users\user\Documents\Visual Studio 11\Projects\MyProject\Application.UI.Web\Services\HttpDependencyInjectionResolver.cs:24
       Application.UI.Web.MvcApplication.Application_Start() in c:\Users\user\Documents\Visual Studio 11\Projects\MyProject\Application.UI.Web\Global.asax.cs:42

    [HttpException (0x80004005): Method not found: 'Autofac.Builder.IRegistrationBuilder`3<!0,!1,!2> Autofac.Builder.IRegistrationBuilder`3.InstancePerMatchingLifetimeScope(System.Object)'.]
       System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9859441
       System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
       System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
       System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
       System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

    [HttpException (0x80004005): Method not found: 'Autofac.Builder.IRegistrationBuilder`3<!0,!1,!2> Autofac.Builder.IRegistrationBuilder`3.InstancePerMatchingLifetimeScope(System.Object)'.]
       System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9873784
       System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
       System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
4

2 回答 2

14

您还需要将Autofac.Integration.Mvc更新到相应的版本。

如果这没有帮助,请确保两个文件的新版本实际上都在执行代码的文件夹中。也许其中之一无法复制到 IIS 文件夹?

于 2013-02-07T15:15:23.707 回答
1

很可能您正在使用与方法不兼容的 asp.net mvc 3InstancePerHttpRequest()

这是找到 autofac mvc 3 contrib (忘记包的名称)。就我而言,升级到 mvc 4 解决了这个问题。

于 2013-06-28T10:47:47.483 回答