This project is read-only.


Infinite loop when auto-resolving unregistered class with unresolvable dependencies


    interface IBar { }
    class Foo
        public Foo(IBar b) { }

    public void Test()
        var container = MunqDependencyResolver.Container;
        var foo = container.Resolve<Foo>(); // infinite loop!
After stepping in, the problem is in the Resolve method. Since Foo is not resolvable, it attempts to auto-register it. It creates a delegate that looks like new Foo(Resolve<IBar>()) and registers that, then recursively calls Resolve. The problem is that Foo is still not resolvable, because IBar cannot be resolved. The auto-resolver does not distinguish between Foo being unregistered and Foo being unresolvable, and so it keeps attempting to register it until it runs out of stack space and crashes.
Closed Mar 9, 2012 at 7:50 PM by mdennis


dfullerton wrote Oct 5, 2011 at 7:03 PM

This seems to fix it. On line 48 of Container.Resolver.cs:
  • return Resolve(name, type);
  • return typeRegistry.Get(name, type).GetInstance();

wrote Oct 20, 2011 at 5:01 PM

wrote Mar 9, 2012 at 7:50 PM

wrote Feb 14, 2013 at 4:01 AM

wrote May 16, 2013 at 9:57 AM