5

I currently have 2 projects in same folder. Main

  • Project1
  • Project2

Problem:

Multiple types were found that match the controller named Account. 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.

The request for Account has found the following matching controllers:

Project1.Controllers.AccountController

Project2.Controllers.AccountController

I using Foundation 4. Thanks advance

Nisarg Patel
  • 260
  • 1
  • 8
April
  • 85
  • 1
  • 2
  • 5

2 Answers2

8

you need to use the version with this signature

public static Route MapRoute(
       this RouteCollection routes,
       string name,
       string url,
       Object defaults,
   string[] namespaces )

To make it work just set up two almost identical routes - one which includes the project1 for the namespaces parameter and then a second identical version but use project2 in the namespaces parameter. That said, it would generally be less confusing, to use different names if you can...

routes.MapRoute(
    name: "Default_Project1",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional,
    namespaces: new string[] { "Project1" } }
);

routes.MapRoute(
    name: "Default_Project2",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional,
    namespaces: new string[] { "Project2" }
);
Code Uniquely
  • 6,356
  • 4
  • 30
  • 40
7

I had the same problem when I copied an MVC project and renamed all the namespaces.

I tried the above solution but it did not work.

Visual Studio was still looking at the old namespace dll's even after I cleaned and rebuilt my project.

So the solution:

  • Right-click solution, click 'Clean Solution'
  • Manually delete everything in the /bin and /obj folders
  • Build your solution
tno2007
  • 1,993
  • 25
  • 16
  • I had done this exact same thing. I copied an MVC project, figuring it was easier to delete the stuff I didn't need than to create everything from scratch (or even copy it over piecemeal), and I was getting this error. This fixed my problem. – Starfleet Security May 21 '16 at 15:32
  • Lifesaver. Had to completely rename a solution/project/namespace and could not find anywhere it was referencing the old Namespace after manually editing all the files. You are a scholar and a gentleman! – Destroigo Feb 13 '20 at 16:00