title: Dependency injection failure on one controller only
body: <p>I have two MVC projects that have identical configuration and they use Unity for depending injection.</p>
  
  <p>The first has 10 controllers and the second one has 20 controllers and dependency injection works perfectly for all of these and has been working well for over a year now.</p>
  
  <p>Today I tried to copy 1 controller from the first project to the second and when I run it I get:</p>
  
  <pre><code>[MissingMethodException: No parameterless constructor defined for this object.]
     System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean&amp; canBeCached, RuntimeMethodHandleInternal&amp; ctor, Boolean&amp; bNeedSecurityCheck) +0
     System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark) +113
     System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark&amp; stackMark) +232
     System.Activator.CreateInstance(Type type, Boolean nonPublic) +83
     System.Activator.CreateInstance(Type type) +6
     System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +55
  
  [InvalidOperationException: An error occurred when trying to create a controller of type 'Web.Admin.Controllers.ApplyController'. Make sure that the controller has a parameterless public constructor.]
     System.Web.Mvc.DefaultControllerActivator.Create(RequestContext requestContext, Type controllerType) +179
     System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType) +80
     System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName) +74
     System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController&amp; controller, IControllerFactory&amp; factory) +197
     System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +49
     System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +50
     System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +16
     System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
     System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155
  </code></pre>
  
  <p>It looks as though for that controller only it applies the DefaultcontrollerActivator instead of the unity one.</p>
  
  <p>I have been going the web.config for over an hour and it seems just fine, unity is registered and all the dependencies, and the Application_Start is identical to the one of the the first project that works with the same controller.
  I can't possibly imagine why everything would work except that one controller.</p>
  
  <p>I tried simplifying the controller to bare basics and this still happens.</p>
  
  <p>I post some code below but I don't think it'll help because I have an identical instance that works and one that doesn't. Either way the application start looks like this:</p>
  
  <pre><code> var container = Ioc.ContainerWrapper.Container as IUnityContainer;
              container
                  .ConfigureAutoRegistration()
                  .ExcludeAssemblies(t =&gt; !t.FullName.StartsWith("Alpari."))
                  .Include(If.ImplementsITypeName, Then.Register())
                  .ApplyAutoRegistration();
  
         container.RegisterType&lt;INHibernateContext, NHibernateContext&gt;();
  
         container.RegisterType&lt;HttpContextBase&gt;(new InjectionFactory(x =&gt; new HttpContextWrapper(HttpContext.Current)));
         container.RegisterType&lt;IAuthentication, FormsAuthenticationWrapper&gt;();
         container.RegisterType&lt;IApplyService, ApplyService&gt;();
  
         /* register loads of interfaces */
         AreaRegistration.RegisterAllAreas();
  
         ViewEngines.Engines.Clear();
         ViewEngines.Engines.Add(new LocalizedViewEngine());
  
         DependencyResolver.SetResolver(new UnityDependencyResolver());
  </code></pre>
  
  <p>The dependency resolver is applied here and this works for all controllers except the ApplyController which seems to be trying to use the default resolver.</p>
  
  <p>The constructor has 10 interfaces but I tried just doing this and I get the same error:</p>
  
  <pre><code>    public ApplyController(IApplyService applyService)
      {
          this.applyService = applyService;
      }
  </code></pre>
  
  <p>At this point I need suggestions as to what could be wrong or how to debug this.</p>