title: ASP.NET MVC - Multiple types were found that match the controller
body: <p>I have what seems to be a common error when two controllers have the same name:</p>
  
  <blockquote>
    <p>Multiple types were found that match the controller named 'Items'.
    This can happen if the route that services this request
    ('{controller}/{action}/{id}') does not specify namespaces to search
    for a controller that matches the request. If this is the case,
    register this route by calling an overload of the 'MapRoute' method
    that takes a 'namespaces' parameter.</p>
    
    <p>The request for 'Items' has found the following matching controllers:</p>
    
    <p>Stock.Controllers.ItemsController</p>
    
    <p>Stock.Areas.Admin.Controllers.ItemsController</p>
  </blockquote>
  
  <p>And this is true as I do have two controllers with this name in different namespaces (as named in the error above). However, most of the fixes I've seen for this is to add the namespace to the default root e.g.</p>
  
  <pre><code>    routes.MapRoute(
          "Default", // Route name
          "{controller}/{action}/{id}", // URL with parameters
          new { controller = "Home", action = "Index", id = UrlParameter.Optional }, // Parameter defaults
          new string[] { "Stock.Controllers" }
      );
  </code></pre>
  
  <p>In my AdminAreaRegistration.cs file the default route that was created was:</p>
  
  <pre><code>    context.MapRoute(
          "Admin_default",
          "Admin/{controller}/{action}/{id}",
          new { action = "Index", id = UrlParameter.Optional }
      );
  </code></pre>
  
  <p>So I tried adding the namespace to that route, but that didn't fix it either e.g.</p>
  
  <pre><code>    context.MapRoute(
          "Admin_default",
          "Admin/{controller}/{action}/{id}",
          new { action = "Index", id = UrlParameter.Optional },
          new string[] { "Stock.Areas.Admin.Controllers" }
      );
  </code></pre>
  
  <p>I've ensured that AreaRegistration.RegisterAllAreas is being called e.g</p>
  
  <pre><code>protected void Application_Start()
  {
      AreaRegistration.RegisterAllAreas();
      FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
      RouteConfig.RegisterRoutes(RouteTable.Routes);
  }
  </code></pre>
  
  <p>Can anyone spot something that I'm missing or suggest something else that I should be doing to get both controllers working?</p>
  
  <p>Thanks</p>