title: ASP MVC ControllerFactory failing on AccountController
body: <p>I'm using Unity and even though I shouldn't have to register my controllers (as far as I'm aware), I get the following error on my AccountController, which is just the one taken from the default MVC template when making a new project.</p>
  
  <pre><code>The IControllerFactory 'WebApplication1.Models.ControllerFactory' did not return a controller for the name 'Account'.
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>[InvalidOperationException: The IControllerFactory 'WebApplication1.Models.ControllerFactory' did not return a controller for the name 'Account'.]
  System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController&amp; controller, IControllerFactory&amp; factory) +336
  System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +50
  System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +48
  System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
  System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +103
  System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155
  </code></pre>
  
  <p>The ControllerFactory looks like this:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using System.Web.Routing;
  using Microsoft.Practices.Unity;
  
  namespace WebApplication1.Models
  {
  public class ControllerFactory : DefaultControllerFactory
  {
      protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
      {
          try
          {
              if (controllerType == null)
              {
                  throw new ArgumentNullException("controllerType");
              }
              if (!typeof(IController).IsAssignableFrom(controllerType))
              {
                  throw new ArgumentException(string.Format("Type requested is not a controller: {0}", controllerType.Name), "controllerType");
              }
              return MvcUnityContainer.Container.Resolve(controllerType) as IController; //This is where it fails
          }
          catch (Exception e)
          {
              return null;
  
          }
      }
  }
  
  public static class MvcUnityContainer
  {
      public static UnityContainer Container { get; set; }
  }
  }
  </code></pre>
  
  <p>The caught exception gives me this:</p>
  
  <pre><code>e = {"Resolution of the dependency failed, type = \"WebApplication1.Controllers.AccountController\", name = \"(none)\".\r\nException occurred while: while resolving.\r\nException is: InvalidOperationException - The current type, Microsoft.AspNet.Identity.IUserS...
  </code></pre>
  
  <p>I have no idea where to go from here, and any help is appreciated.</p>
  
  <p>UPDATE:</p>
  
  <p>AccountController class:</p>
  
  <pre><code>[Authorize]
  public class AccountController : Controller
  {
      private ApplicationSignInManager _signInManager;
      private ApplicationUserManager _userManager;
  
      public AccountController()
      {
      }
  
      public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager)
      {
          UserManager = userManager;
          SignInManager = signInManager;
      }
  
      public ApplicationSignInManager SignInManager
      {
          get
          {
              return _signInManager ?? HttpContext.GetOwinContext().Get&lt;ApplicationSignInManager&gt;();
          }
          private set
          {
              _signInManager = value;
          }
      }
  
      public ApplicationUserManager UserManager
      {
          get
          {
              return _userManager ?? HttpContext.GetOwinContext().GetUserManager&lt;ApplicationUserManager&gt;();
          }
          private set
          {
              _userManager = value;
          }
      }
  
      //
      // GET: /Account/Login
      [AllowAnonymous]
      public ActionResult Login(string returnUrl)
      {
          ViewBag.ReturnUrl = returnUrl;
          return View();
      }
  }
  </code></pre>
  
  <p>UPDATE 2: </p>
  
  <p>As suggested by Steven, I've removed the try-catch from the factory and get this exception:</p>
  
  <pre><code>An exception of type 'Microsoft.Practices.Unity.ResolutionFailedException' occurred in Microsoft.Practices.Unity.dll but was not handled in user code
  
  Additional information: Resolution of the dependency failed, type = "WebApplication1.Controllers.AccountController", name = "(none)".
  
  Exception occurred while: while resolving.
  
  Exception is: InvalidOperationException - The current type, Microsoft.AspNet.Identity.IUserStore`1[WebApplication1.Models.ApplicationUser], is an interface and cannot be constructed. Are you missing a type mapping?
  
  -----------------------------------------------
  
  At the time of the exception, the container was:
  
  
  
    Resolving WebApplication1.Controllers.AccountController,(none)
  
    Resolving parameter "userManager" of constructor WebApplication1.Controllers.AccountController(WebApplication1.ApplicationUserManager userManager, WebApplication1.ApplicationSignInManager signInManager)
  
      Resolving WebApplication1.ApplicationUserManager,(none)
  
      Resolving parameter "store" of constructor WebApplication1.ApplicationUserManager(Microsoft.AspNet.Identity.IUserStore`1[[WebApplication1.Models.ApplicationUser, WebApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] store)
  
        Resolving Microsoft.AspNet.Identity.IUserStore`1[WebApplication1.Models.ApplicationUser],(none)
  </code></pre>