Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activation error occurred while trying to get instance of type AccountController, key \"\""

That's my AccountController:

[Authorize]
public class AccountController : Controller
{
    private UserManager<User> _userManager { get; set; }

    public AccountController() : this(new UserManager<User>(new UserStore())) {}

    public AccountController(UserManager<User> userManager) {
        _userManager = userManager;
    }
}

And stack trace:

Microsoft.Practices.ServiceLocation.ActivationException was unhandled by user code
  HResult=-2146233088
  Message=Activation error occurred while trying to get instance of type AccountController, key ""
  Source=Microsoft.Practices.ServiceLocation
  StackTrace:
       at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 53
       at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType) in c:\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 34
       at System.Web.Mvc.DependencyResolver.DelegateBasedDependencyResolver.GetService(Type type)
  InnerException: StructureMap.StructureMapException
       HResult=-2146232832
       Message=StructureMap Exception Code:  202
No Default Instance defined for PluginFamily Microsoft.AspNet.Identity.IUserStore`1[[Fables.BLL.Entities.User, Fables.BLL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Microsoft.AspNet.Identity.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
       Source=StructureMap
       ErrorCode=202
       StackTrace:
            at StructureMap.BuildSession.<.ctor>b__0(Type t) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 33
            at StructureMap.Util.Cache`2.get_Item(KEY key) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Util\Cache.cs:line 83
            at StructureMap.BuildSession.CreateInstance(Type pluginType) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 215
            at StructureMap.Pipeline.DefaultInstance.build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\DefaultInstance.cs:line 22
            at StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:line 103
            at StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:line 69
            at StructureMap.Pipeline.ConstructorInstance.Get(String propertyName, Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:line 74
            at StructureMap.Pipeline.ConstructorInstance.Get[T](String propertyName, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:line 79
            at StructureMap.Pipeline.Arguments.Get[T](String propertyName) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Arguments.cs:line 18
            at lambda_method(Closure , IArguments )
            at StructureMap.Construction.BuilderCompiler.FuncCompiler`1.<>c__DisplayClass2.<CreateBuilder>b__0(IArguments args) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Construction\BuilderCompiler.cs:line 56
            at StructureMap.Construction.InstanceBuilder.BuildInstance(IArguments args) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Construction\InstanceBuilder.cs:line 34
            at StructureMap.Pipeline.ConstructorInstance.Build(Type pluginType, BuildSession session, IInstanceBuilder builder) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:line 237
            at StructureMap.Pipeline.ConstructorInstance.build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:line 218
            at StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:line 103
            at StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:line 69
            at StructureMap.Pipeline.ObjectBuilder.ConstructNew(Type pluginType, Instance instance, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ObjectBuilder.cs:line 39
            at StructureMap.Pipeline.ObjectBuilder.Resolve(Type pluginType, Instance instance, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ObjectBuilder.cs:line 27
            at StructureMap.BuildSession.CreateInstance(Type pluginType, Instance instance) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 176
            at StructureMap.BuildSession.<>c__DisplayClass3.<.ctor>b__1() in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 36
            at StructureMap.BuildSession.CreateInstance(Type pluginType) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 215
            at StructureMap.Pipeline.DefaultInstance.build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\DefaultInstance.cs:line 22
            at StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:line 103
            at StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:line 69
            at StructureMap.Pipeline.ConstructorInstance.Get(String propertyName, Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:line 74
            at StructureMap.Pipeline.ConstructorInstance.Get[T](String propertyName, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:line 79
            at StructureMap.Pipeline.Arguments.Get[T](String propertyName) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Arguments.cs:line 18
            at lambda_method(Closure , IArguments )
            at StructureMap.Construction.BuilderCompiler.FuncCompiler`1.<>c__DisplayClass2.<CreateBuilder>b__0(IArguments args) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Construction\BuilderCompiler.cs:line 56
            at StructureMap.Construction.InstanceBuilder.BuildInstance(IArguments args) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Construction\InstanceBuilder.cs:line 34
            at StructureMap.Pipeline.ConstructorInstance.Build(Type pluginType, BuildSession session, IInstanceBuilder builder) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:line 237
            at StructureMap.Pipeline.ConstructorInstance.build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ConstructorInstance.cs:line 218
            at StructureMap.Pipeline.Instance.createRawObject(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:line 103
            at StructureMap.Pipeline.Instance.Build(Type pluginType, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\Instance.cs:line 69
            at StructureMap.Pipeline.ObjectBuilder.ConstructNew(Type pluginType, Instance instance, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ObjectBuilder.cs:line 39
            at StructureMap.Pipeline.ObjectBuilder.Resolve(Type pluginType, Instance instance, BuildSession session) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Pipeline\ObjectBuilder.cs:line 27
            at StructureMap.BuildSession.CreateInstance(Type pluginType, Instance instance) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 176
            at StructureMap.BuildSession.<>c__DisplayClass3.<.ctor>b__1() in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 36
            at StructureMap.BuildSession.CreateInstance(Type pluginType) in c:\BuildAgent\work\767273992e840853\src\StructureMap\BuildSession.cs:line 215
            at StructureMap.Container.GetInstance(Type pluginType) in c:\BuildAgent\work\767273992e840853\src\StructureMap\Container.cs:line 265
            at Fables.Web.DependencyResolution.StructureMapDependencyScope.DoGetInstance(Type serviceType, String key) in f:\MyProjects\Fables\Fables\Fables.Web\DependencyResolution\StructureMapDependencyScope.cs:line 123
            at Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) in c:\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:line 49
       InnerException: 

Can somebody explain please, what is this exception mean and how to resolve it? Ty.

like image 337
Maxim Zhukov Avatar asked Mar 10 '14 10:03

Maxim Zhukov


1 Answers

Your app is using the second constructor as StructureMap will automatically select the "greediest" public constructor of a class to use for injection. You can check this behaviour on the StructureMap documents.

So by looking at the error it looks like you are missing a mapping from IUserStore<User> to your UserStore class in StructureMap.

If you want StructureMap to use your parameterless constructor, you first need to make sure that StructureMap is creating the AccountController instance. Then you need to update your StructureMap registry code to specify which constructor should be used. (See a similar question here). This is also explained in the documentation

like image 195
Daniel J.G. Avatar answered Oct 30 '22 03:10

Daniel J.G.