Weird exception after updated Autofac

喜你入骨 提交于 2019-12-08 17:22:50

问题


I have an MVC4 application before, I've updated version of Autofac, every thing worked ok, now i have this weird exception.

Please help!?

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();

Stack trace:

 [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

回答1:


You also need to update Autofac.Integration.Mvc to the corresponding version.

If that doesn't help, make sure that the new versions of both files are actually in the folder the code is executed from. Maybe one of them couldn't be copied to the IIS folder?




回答2:


It might well be that you are using asp.net mvc 3 which has incompatibilities with method InstancePerHttpRequest()

which is found autofac mvc 3 contrib (forgot the name of the package). In my case upgrading to the mvc 4 fixed the issue.



来源:https://stackoverflow.com/questions/14754479/weird-exception-after-updated-autofac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!