0

I have two web projects in the same solution, the first starts and the second gives me an error:

"Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('Home / {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. "

I specify that :

  • The two projects have a different namespace (Intranet / Extranet).
  • The two projects are completely independent.
  • The two projects do not reference each other.
  • I DO NOT want to add a zone.
  • The two projects are (in development) hosted on my local IIS, each with a different domain name (intranet.lan / extranet.lan).

I don't understand how to tell Visual Studio not to look in other projects. This behavior is really abnormal, I think it is a bug or a very bad design strategy.

I also presume that I have read a lot of post dealing with the subject without ever finding any answer. Everyone creates an area (I don't want to, because it's not "clean" creating an area in a project just for the project is something totally stupid and illogical).

If anyone can help me it would be very nice.

Edit:

I place my Extranet project in a separate directory, I create a new solution and I add it. I configure it to launch under IIS Express and it also tells me that it finds two controllers. That of Intranet and Extranet. However Ctrl + F with "Intranet" in the extranet project gives no results. I also opened the project and solution file and I cannot find any reference to Intranet. It's incredible, the Intranet project seems to be linked to extranet but without any reference or ponitage whatsoever in the code. Even after rebuild the project.

Edit2:

I tried with

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

Or

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    namespaces: new[] { "Extranet.Controllers" }
);

But no effect.

Mayzz
  • 116
  • 1
  • 9
  • Does this answer your question? [Multiple types were found that match the controller named 'Home'](https://stackoverflow.com/questions/7842293/multiple-types-were-found-that-match-the-controller-named-home) – Pedro Coelho Feb 25 '20 at 22:16
  • @PedroCoelho The problem with this solution is that it forces to define the controller as an additional parameter. It is therefore a heresy because it is no longer a route at all. You have to define as many routes as there are controllers. – Mayzz Feb 25 '20 at 22:23
  • Completely crazy behavior. I place my Extranet project in a separate directory, I create a new solution and I add it. I configure it to launch under IIS Express and it also tells me that it finds two controllers. That of Intranet and Extranet. However Ctrl + F with "Intranet" in the extranet project gives no results. I also opened the project and solution file and I cannot find any reference to Intranet. It's incredible, the Intranet project seems to be linked to extranet but without any reference or ponitage whatsoever in the code. Even after rebuild the project. – Mayzz Feb 25 '20 at 23:59

1 Answers1

1

After several searches I finally found it. It was actually necessary to specify the namespace in the route for each project like this :

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    namespaces: new[] { "Intranet.Controllers" }
);

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    namespaces: new[] { "Extranet.Controllers" }
);

But cleaning and regenerating the solution is not enough. It was also necessary to delete the content of bin / obj and regenerate the project. I reported this bug to Microsoft because I searched for hours because of it. I had confidence in cleaning the project, I shouldn't have.

Multiple types were found that match the controller named 'Account'. MVC 4 & using RouteConfig.CS

Big thanks to @tno2007

Mayzz
  • 116
  • 1
  • 9