Error after update Autofac.Mvc5 from 3.3.2 to 3.3.

2019-07-15 20:30发布

I have a Error after update Autofac.Mvc5 from 3.3.2 to 3.3.3 I posted my issue to github https://github.com/autofac/Autofac/issues/572#issuecomment-63236738 and got response that I need to ask here :)

Below my situation:

What I have:

// Setup DI as default MVC controller factory
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

I need this to use in injected property of Custom Membership Provider

protected IMembershipService MembershipService
{
    get
    {
         return DependencyResolver.Current.GetService();
    }
}

issue: The dependency resolver is not of type 'Autofac.Integration.Mvc.AutofacDependencyResolver'

Please help me to solve this.

UPDATE So now I have such error after update from 3.3.2 to

The dependency resolver is not of type 'Autofac.Integration.Mvc.AutofacDependencyResolver' and does not appear to be wrapped using DynamicProxy from the Castle Project. This issue could be the result of a change in the DynamicProxy implementation or the use of a different proxy library to wrap the dependency resolver.

Any Ideas on how to solve that?

url to image error http://i.stack.imgur.com/yJJXX.png

UPDATE Here what i found github.com/autofac/Autofac/blob/82cc138596e74095f50720319feb2a2ce734310d/Core/Source/Autofac.Integration.Mvc/AutofacDependencyResolver.cs on this file we have part where exception throws for such text. This is only one part in all source code, so I think I need to move forward and find out why I'm getting this issue. Also when and why my code request this method AutofacDependencyResolver.Current. As I checked that I have NO direct calls of AutofacDependencyResolver.Current. I need to investigate other variants (places) of calls.

3条回答
老娘就宠你
2楼-- · 2019-07-15 20:51

i was not working for me this line:

 Autofac_RegisterApplicationModules(builder);

so i changed it by this:

  RegisterAssemblyModules(builder);

and it works now.

Thanks for the solution!

查看更多
干净又极端
3楼-- · 2019-07-15 20:56

I had the same issue.

It is due to MvcSiteMapProvider using it's own DI.

You can resolve the issue by making use of the NuGet package MvcSiteMapProvider MVC5 Autofac Dependency Injection Configuration and setting up Autofac as described in the readme for this project.

查看更多
男人必须洒脱
4楼-- · 2019-07-15 21:15

For now I see such resolution

        // Create DI container
        var builder = new ContainerBuilder();

        // Register application modules
        Autofac_RegisterApplicationModules(builder);

        // Register filter provider
        //builder.RegisterFilterProvider();

        // Register MVC specific abstractions (HttpRequestBase,HttpResponceBase etc)
        builder.RegisterModule(new AutofacWebTypesModule());

        // container
        var container = builder.Build();

As you can see I commented this row

//builder.RegisterFilterProvider();

BUT I need confirmation if that is ok!

Please, who knows explain if it is correct and/or how to be.

TRACE RESULT BELOW - NEED HELP

[InvalidOperationException: The dependency resolver is not of type 'Autofac.Integration.Mvc.AutofacDependencyResolver' and does not appear to be wrapped using DynamicProxy from the Castle Project. This issue could be the result of a change in the DynamicProxy implementation or the use of a different proxy library to wrap the dependency resolver.]
   Autofac.Integration.Mvc.AutofacDependencyResolver.get_Current() +367
   Autofac.Integration.Mvc.AutofacFilterProvider.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +196
   System.Web.Mvc.FilterProviderCollection.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +279
   System.Web.Mvc.ControllerActionInvoker.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +62
   System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +436
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) +82
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +73
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +151
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) +105
   System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +588
   System.Web.Mvc.Controller.<BeginExecute>b__14(AsyncCallback asyncCallback, Object callbackState, Controller controller) +47
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +65
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +151
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) +139
   System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +484
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +50
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) +98
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +73
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +151
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) +106
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +446
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +88
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +50
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

After my new investigation I found out the issue. My website uses MVCSiteMap

http://i.stack.imgur.com/7xnul.png

I am checking now on how to configure MvcSiteMapProvider to not change DI.

<add key="MvcSiteMapProvider_UseExternalDIContainer" value="false" />

So I think that I need to change it to true to solve issue. I am in progress on it now and let you know soon.

Feel free to update my view if you have solution!

查看更多
登录 后发表回答