ninject / Ninject.Web.Mvc

extension for ninject providing integration with ASP.NET MVC
http://ninject.org/
Other
238 stars 85 forks source link

Error activating IFilterProvider using binding from IFilterProvider to NinjectFilterAttributeFilterProvider #13

Closed andyhot closed 12 years ago

andyhot commented 13 years ago

A cyclical dependency was detected between the constructors of two services. Activation path: 1) Request for IFilterProvider

I keep getting this in a production server after a few hours of flawless execution. I don't see any other exceptions in the elmah logs and my current guess is that the server is reloading/restarting the app somehow and this leads to the exceptions. Of course, once those appear, the whole app is unusable.

I'm using Ninject 2.2.0.0 and Ninject.Web.Mvc 2.2.0.3 and extend NinjectHttpApplication in my Global.asax.cs (Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1; ASP.MVC 3)

Here's the full trace

[ActivationException: Error activating IFilterProvider using binding from IFilterProvider to NinjectFilterAttributeFilterProvider
A cyclical dependency was detected between the constructors of two services.

Activation path:
  1) Request for IFilterProvider

Suggestions:
  1) Ensure that you have not declared a dependency for IFilterProvider on any implementations of the service.
  2) Consider combining the services into a single one to remove the cycle.
  3) Use property injection instead of constructor injection, and implement IInitializable
     if you need initialization logic to be run after property values have been injected.
]
   Ninject.Activation.Context.Resolve() in d:\BuildAgent-01\work\b68efe9aafe8875e\src\Ninject\Activation\Context.cs:148
   Ninject.KernelBase.b__7(IContext context) in d:\BuildAgent-01\work\b68efe9aafe8875e\src\Ninject\KernelBase.cs:375
   System.Linq.<>c__DisplayClass12`3.b__11(TSource x) +32
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +151
   System.Linq.d__b1`1.MoveNext() +92
   System.Linq.d__71`1.MoveNext() +117
   System.Linq.d__14`2.MoveNext() +399
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +217
   System.Linq.d__0.MoveNext() +96
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +217
   System.Linq.d__a0`1.MoveNext() +93
   System.Web.Mvc.d__b.MoveNext() +131
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +217
   System.Linq.d__a0`1.MoveNext() +93
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +87
   System.Linq.d__aa`1.MoveNext() +88
   System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection) +395
   System.Web.Mvc.FilterInfo..ctor(IEnumerable`1 filters) +248
   System.Web.Mvc.ControllerActionInvoker.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +47
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +128
   System.Web.Mvc.Controller.ExecuteCore() +115
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +94
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
   System.Web.Mvc.<>c__DisplayClassb.b__5() +37
   System.Web.Mvc.Async.<>c__DisplayClass1.b__0() +21
   System.Web.Mvc.Async.<>c__DisplayClass8`1.b__7(IAsyncResult _) +12
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +55
   System.Web.Mvc.<>c__DisplayClasse.b__d() +31
   System.Web.Mvc.SecurityUtil.b__0(Action f) +7
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +23
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +59
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8841105
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
remogloor commented 13 years ago

This is a very strange error message and it should not be possible to occur. The only active request is for IFilterProvider but it seems that it is already on the active bindings stack. I doubt that it is a problem of the MVC3 extension more likely it is a porblem in Ninject Core but I can't see any way such a behavior can occur yet.

Can you debug the application? If so can you please break at Ninject\Activation\Context.cs:148 and tell me the values of Binding and Request.ActiveBindings?

remogloor commented 13 years ago

Fixed in 2.2.1.0

andyhot commented 13 years ago

thx - will try it soon - was the fix in 49471e030e5ab8a59de1e8128c04d241f9b9e2fd ?

remogloor commented 13 years ago

The commit fixing the issue is https://github.com/ninject/ninject.web.mvc/commit/ebc359a6aa5e13b32cd2bca509037c11a690309f

andyhot commented 13 years ago

fix works great - thx

Axlns commented 12 years ago

This exact error message still happens for us in very latest version of Ninject. We have 3 NuGet packages installed

Ninject (3.0.1.10) Ninject.Web.Common (3.0.0.7) Ninject.MVC3 (3.0.0.6)

I cant repeat that all the time, usually it happens after dozens of successful AJAX requests, and then this happens and entire application is broken. To fix it I have to restart app (recycly app pool or rebuild app in Visual Studio)

Right now this happening in MVC4 .NET 4.5 application, but we experienced the same error in MVC3 application as well

Any help in understanding why this is happening will be really appreciated. Thanks

Below exact stack trace.

Error activating IFilterProvider using binding from IFilterProvider to NinjectFilterProvider A cyclical dependency was detected between the constructors of two services.

Activation path: 1) Request for IFilterProvider

Suggestions: 1) Ensure that you have not declared a dependency for IFilterProvider on any implementations of the service. 2) Consider combining the services into a single one to remove the cycle. 3) Use property injection instead of constructor injection, and implement IInitializable if you need initialization logic to be run after property values have been injected. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Ninject.ActivationException: Error activating IFilterProvider using binding from IFilterProvider to NinjectFilterProvider A cyclical dependency was detected between the constructors of two services.

Activation path: 1) Request for IFilterProvider

Suggestions: 1) Ensure that you have not declared a dependency for IFilterProvider on any implementations of the service. 2) Consider combining the services into a single one to remove the cycle. 3) Use property injection instead of constructor injection, and implement IInitializable if you need initialization logic to be run after property values have been injected.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ActivationException: Error activating IFilterProvider using binding from IFilterProvider to NinjectFilterProvider A cyclical dependency was detected between the constructors of two services.

Activation path: 1) Request for IFilterProvider

Suggestions: 1) Ensure that you have not declared a dependency for IFilterProvider on any implementations of the service. 2) Consider combining the services into a single one to remove the cycle. 3) Use property injection instead of constructor injection, and implement IInitializable if you need initialization logic to be run after property values have been injected. ] Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:148 System.Linq.WhereSelectListIterator2.MoveNext() +245 System.Linq.<CastIterator>d__b11.MoveNext() +296 System.Linq.d71`1.MoveNext() +344 System.Linq.d142.MoveNext() +578 System.Linq.Buffer1..ctor(IEnumerable1 source) +520 System.Linq.<GetEnumerator>d__0.MoveNext() +252 System.Linq.Buffer1..ctor(IEnumerable1 source) +520 System.Linq.<ReverseIterator>d__a01.MoveNext() +141 System.Web.Mvc.db.MoveNext() +520 System.Linq.Buffer1..ctor(IEnumerable1 source) +520 System.Linq.da01.MoveNext() +141 System.Linq.WhereSelectEnumerableIterator2.MoveNext() +165 System.Collections.Generic.List1..ctor(IEnumerable1 collection) +536 System.Linq.Enumerable.ToList(IEnumerable1 source) +80 System.Web.Mvc.FilterInfo..ctor(IEnumerable1 filters) +347 System.Web.Mvc.ControllerActionInvoker.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +46 System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +257 System.Web.Mvc.<>cDisplayClass1d.b17(AsyncCallback asyncCallback, Object asyncState) +50 System.Web.Mvc.Async.WrappedAsyncResult1.Begin(AsyncCallback callback, Object state, Int32 timeout) +146 System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate1 endDelegate, Object tag, Int32 timeout) +166 System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +543 System.Web.Mvc.Async.WrappedAsyncResult1.Begin(AsyncCallback callback, Object state, Int32 timeout) +146 System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate1 endDelegate, Object tag, Int32 timeout) +166 System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate endDelegate, Object tag) +27 System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +409 System.Web.Mvc.<>cDisplayClass8.b2(AsyncCallback asyncCallback, Object asyncState) +144 System.Web.Mvc.Async.WrappedAsyncResult1.Begin(AsyncCallback callback, Object state, Int32 timeout) +146 System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate1 endDelegate, Object tag, Int32 timeout) +166 System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object state, BeginInvokeDelegate beginDelegate, EndInvokeDelegate endDelegate, Object tag) +27 System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +364 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +12551795 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +288

cosmo777 commented 12 years ago

Same

remogloor commented 12 years ago

Can you confirm that you are not using any custom IDependencyResolver implementation but the one from Ninject.Web.MVC3?

cosmo777 commented 12 years ago

I just confirmed that I was using a custom IDependencyResolver. Switching to the one from the Ninject.Web.MVC3 assembly fixed my problem. Thanks for making me check and and sorry for the red herring :-) love the product.

fabiosilvalima commented 11 years ago

It hapened right now for me... It's a shame. I was using a custom implementation of IDependencyResolver and I have changed to Ninject.Web.Mvc.NinjectDependencyResolver. I'm testing with no errors. It seems to fixed. I have 4 applications working with the same dll. That error just happend on the fifth application.

thank you

najamsk commented 10 years ago

I am also having this issue I am using following implementation to setup my implementation with interfaces in my mvc project.

namespace MoftakSolutions.WebUI.Infrastructure { public class NinjectDependencyResolver : IDependencyResolver { private IKernel kernel;

    public NinjectDependencyResolver() {
        kernel = new StandardKernel();
        AddBindings();
    }

    public object GetService(Type serviceType) {
        return kernel.TryGet(serviceType);
    }

    public IEnumerable<object> GetServices(Type serviceType) {
        return kernel.GetAll(serviceType);
    }

    public IBindingToSyntax<T> Bind<T>() {
        return kernel.Bind<T>();
    }

    public IKernel Kernel {
        get { return kernel; }
    }

    private void AddBindings() {

        // put additional bindings here
        //kernel.Inject(Roles.Provider);
        Bind<NewsletterSubscribersService>().To<NewsletterSubscribersService>().WithConstructorArgument("repo", new NewsletterSubscribersRepository());
        Bind<JobsService>().To<JobsService>().WithConstructorArgument("repo", new JobsRepository());
        Bind<NewsService>().To<NewsService>().WithConstructorArgument("repo", new NewsRepository());

        // create the email settings object

    }
}
Marusyk commented 8 years ago

This exact error message still happens for me in the last version of Ninject