Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error after update Autofac.Mvc5 from 3.3.2 to 3.3.3 #572

Closed
posledam opened this issue Sep 14, 2014 · 20 comments
Closed

Error after update Autofac.Mvc5 from 3.3.2 to 3.3.3 #572

posledam opened this issue Sep 14, 2014 · 20 comments

Comments

@posledam
Copy link

Everything worked fine until I updated the library. Now I get the following message:

"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."

Apparently this is due to this update: #568

Please tell me what to do or how to fix it?

@tillig
Copy link
Member

tillig commented Sep 16, 2014

This occurs when attempting to access AutofacDependencyResolver.Current. The AutofacDependencyResolver.Current implementation first attempts to see if the DependencyResolver.Current is an AutofacDependencyResolver and return that. If it's not AutofacDependencyResolver, it does some magic to see if you're using Glimpse and locates the AutofacDependencyResolver from there.

If neither of these is the case, then you get this exception.

Look at the stack trace in the exception. In your application, set a breakpoint in your code where you're accessing AutofacDependencyResolver.Current and getting the exception.

What is inside DependencyResolver.Current at that time? Is it null? Is it the "default dependency resolver" from MVC? Is it something else? What is the type?

If you can't figure it out, can you post a small repro that shows the issue?

@posledam
Copy link
Author

Thanks for the answer, I'll do an example to demonstrate the error

@mubeda
Copy link

mubeda commented Oct 13, 2014

I have the same problem after updating to Autofac.Mvc5 3.3.3. Also i'm using
Autofac.Extras.CommonServiceLocator 3.2.0.0
Autofac.Integration.Mvc 3.3.0.0
Autofac 3.5.0.0

Registration code:

       var builder = new ContainerBuilder();
       ...
        //finish registration

        builder.RegisterFilterProvider();
        builder.RegisterType<AutofacDependencyResolver>()
            .AsSelf()
            .AsImplementedInterfaces()
            .SingleInstance(); 

        _container = builder.Build();
        var resolver = new AutofacDependencyResolver(_container);
        DependencyResolver.SetResolver(resolver);
        var locator = new AutofacServiceLocator(_container);
        ServiceLocator.SetLocatorProvider(() => locator);

ServiceLocator is Microsoft.Practices.ServiceLocation
Is there any tip to fix the problem?

@mubeda
Copy link

mubeda commented Oct 13, 2014

I found the solution for my problem. I replaced this line of code

        builder.RegisterControllers(Assembly.GetExecutingAssembly());

with this one

        builder.RegisterControllers(typeof(MvcApplication).Assembly);

@tillig
Copy link
Member

tillig commented Oct 13, 2014

@hVostt Since no repro has come in for this, I assume you've solved your issue. Feel free to post the repro and re-open if that's not the case.

@mubeda The problem in your code is possibly unrelated. You should not be manually registering AutofacDependencyResolver. That happens internally for you. If you continue to see trouble, please file a new issue.

@tillig tillig closed this as completed Oct 13, 2014
@rodchenkov
Copy link

Hello.

I have issue after this update.
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();
}
}

Please help me to solve this.

Best Regards.

@tillig
Copy link
Member

tillig commented Nov 16, 2014

@rodchenkov This would be a great question to ask on StackOverflow. Include this code as well as a description of what's wrong and the things you've tried to solve the issue.

@rodchenkov
Copy link

Hi can you please explain this issue
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.

@tillig
Copy link
Member

tillig commented Nov 26, 2014

I explained the error in the first response in this issue. Scroll up and read the entire thread from the top.

@rodchenkov
Copy link

Hi I saw your comment but I can not understand why this happened with me when I updated Autofac.MVC5 from 3.3.2 to version 3.3.3?
Can you please explain in more details?

@tillig
Copy link
Member

tillig commented Nov 27, 2014

There's really not anymore to it. The exception comes from somewhere in your code where you're trying to access AutofacDependencyResolver. When your code is accessing AutofacDependencyResolver.Current it's doing so at a time when we're not able to convert the DependencyResolver.Current into an AutofacDependencyResolver.

Truly, that's it. If it's happening after upgrade then it's something you were doing in your code that you probably shouldn't have been doing, like accessing AutofacDependencyResolver.Current before you set the resolver - something at application startup, for example.

The original comment on this issue provides some tips on how to troubleshoot it. Look at the stack trace the exception is giving you. It should tell you where in your code it's happening. Debug from there. Doing the actual debugging is not something we can help you with.

If you do need help, it would probably be good to follow up on StackOverflow and tag your question autofac instead of continuing in this issue. I think from an "issue" standpoint, we've provided all we can here. There is a large community of folks out there, including us, waiting to help on StackOverflow and solving things over there will also help the rest of the community seeing this problem to learn.

If you post to StackOverflow, be sure to include the part in your code that is accessing AutofacDependencyResolver.Current and is generating the exception. Also be sure to include information about what you've done to debug it and information about when you're actually setting the current dependency resolver to Autofac. People will need all that information to help you.

@rodchenkov
Copy link

Thank you for your reply, but I have no code that uses DependencyResolver.Current or AutofacDependencyResolver.Current
Is that possible that this maybe requested by Autofac dll? Or maybe because of other conditions?

@tillig
Copy link
Member

tillig commented Nov 27, 2014

At this point we need a lot more information - all the information you would post to StackOverflow - in order to say. Please post to StackOverflow the following information and put a link here to the question on StackOverflow:

  • The list of the versions of all packages and dependencies you're using.
  • The full stack trace with any InnerException information so it shows a full picture of what's going on.
  • If possible, a reproduction showing how to get the error to appear.
  • A list of the steps you've taken to try debugging the issue. (Have you set any breakpoints at the place where the exception originates? What did you see? Did you try upgrading dependencies? What else have you tried?)

Again, please post that information to StackOverflow and tag the question autofac so that we can also enlist the help of the rest of the community and help other people learn from the experience. Then post just the link to the question back here and we'll follow up on SO. Thanks!

@tillig
Copy link
Member

tillig commented Nov 27, 2014

Oh, it looks like you've already started the question here:
http://stackoverflow.com/questions/27049417/error-after-update-autofac-mvc5-from-3-3-2-to-3-3-3

As noted by many commenters in there, a lot more information is required to help you. Please update your question with all of the information I noted above. I will also include the list of things we need in comments on that question. We can continue this on your StackOverflow question so there is one consistent single location where all the information is gathered.

@rodchenkov
Copy link

Ok thanks! We do it so.

@rodchenkov
Copy link

Hi We found issue with this update.
If we are adding builder.RegisterFilterProvider(); FilterAttribute injections doesn't work.
e.g. MyCustomAuthenticateAttribute even not fire!

Below is stacktrace

[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.b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) +82
System.Web.Mvc.Async.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +73 System.Web.Mvc.Async.WrappedAsyncResultBase1.Begin(AsyncCallback callback, Object state, Int32 timeout) +151
System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object callbackState, BeginInvokeDelegate1 beginDelegate, EndInvokeVoidDelegate1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) +105
System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +588
System.Web.Mvc.Controller.b__14(AsyncCallback asyncCallback, Object callbackState, Controller controller) +47
System.Web.Mvc.Async.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +65 System.Web.Mvc.Async.WrappedAsyncResultBase1.Begin(AsyncCallback callback, Object state, Int32 timeout) +151
System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object callbackState, BeginInvokeDelegate1 beginDelegate, EndInvokeVoidDelegate1 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.b__4(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) +98
System.Web.Mvc.Async.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +73 System.Web.Mvc.Async.WrappedAsyncResultBase1.Begin(AsyncCallback callback, Object state, Int32 timeout) +151
System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object callbackState, BeginInvokeDelegate1 beginDelegate, EndInvokeVoidDelegate1 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

http://stackoverflow.com/questions/27049417/error-after-update-autofac-mvc5-from-3-3-2-to-3-3-3/27189744#27189744

@tillig
Copy link
Member

tillig commented Jan 8, 2015

@rodchenkov Again, please update your SO question with this information and expect responses there rather than in this issue.

@madelson
Copy link

madelson commented Apr 7, 2015

@tillig I just updated to Autofac.Mvc5 3.3.3 from 3.3.2 and saw the same issue appear. As the OP said, this happens deep in the MVC stack, but seems related to filters:

at Autofac.Integration.Mvc.AutofacDependencyResolver.get_Current()
at Autofac.Integration.Mvc.AutofacFilterProvider.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
at System.Web.Mvc.FilterProviderCollection.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
at System.Web.Mvc.ControllerActionInvoker.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state)
at System.Web.Mvc.Controller.b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback callback, Object state, Int32 timeout)
at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TState](AsyncCallback callback, Object callbackState, BeginInvokeDelegate1 beginDelegate, EndInvokeVoidDelegate1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext)
at System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TState](AsyncCallback callback, Object callbackState, BeginInvokeDelegate1 beginDelegate, EndInvokeVoidDelegate1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) at System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.b__4(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback callback, Object callbackState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncResultWrapper.Begin[TState](AsyncCallback callback, Object callbackState, BeginInvokeDelegate1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext)
at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

@TimSirmovics
Copy link

I had the same issue.

Turns out it is due to MvcSiteMapProvider using it's own DI.
You have to configure MvcSiteMapProvider to use Autofac (There is a NuGet package for this).

@tillig
Copy link
Member

tillig commented Aug 26, 2015

Since the time this was opened I've added some documentation on challenges with AutofacDependencyResolver.Current as well as an issue that may help mitigate some of these challenges.

Most likely changes and questions related to this will be addressed in the MVC repository rather than here.

Future readers: If you have this issue, please read the updated documentation and if you still feel like you need help, ask a question on StackOverflow with the autofac tag or chime in on the workaround issue.

@autofac autofac locked and limited conversation to collaborators Aug 26, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants