Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename ASP.NET MVC project resulting in multiple types for controller error

This has happenned before and I can't remember how I solved it. I renamed an MVC project then did a ReSharper refactor to update the namespaces. Now when I run I get the following error when I run the project:

Multiple types were found that match the controller named 'Dashboard'. 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 'Dashboard' has found the following matching controllers: EkmDomains.FrontEnd.Controllers.DashboardController EkmDomains.Web.Controllers.DashboardController 

I have done a search for everywhere in the solution where the old EkmDomains.FrontEnd namespace ocurrs and replaced it with the new one but to no avail...

Anyone have any ideas?

like image 544
jcvandan Avatar asked Jun 16 '11 15:06

jcvandan


People also ask

Can we have two action methods with same name in MVC?

While ASP.NET MVC will allow you to have two actions with the same name, . NET won't allow you to have two methods with the same signature - i.e. the same name and parameters. You will need to name the methods differently use the ActionName attribute to tell ASP.NET MVC that they're actually the same action.

How do I Rename a controller in Visual Studio?

With Visual Studio: Highlight the controller name in your editor, and press F2. You'll have to rename folders yourself. Alternatively, install Resharper and use the refactoring in it... it makes renaming directories and files very easy, but requires a little bit of time to learn it. Save this answer.


2 Answers

Adding a few more for anyone else. These cost me an hour of my life that I'm not getting back.

  1. Delete not only \bin files, but also \obj\debug and \release too.

  2. Delete temporary ASP.NET files.

  3. Check for any references to old DLL name in web.config.

  4. Check all web.config files. Sometimes one is added to the Views folder too.

like image 33
douglas.kirschman Avatar answered Sep 29 '22 09:09

douglas.kirschman


Haha I just remembered how I did it last time - you have to manually delete the old dll's from the bin folder. Doing a clean doesn't get rid of them because a clean only delete's DLL's that match the project name - hence it leaves the DLL's with the old project name.

like image 143
jcvandan Avatar answered Sep 29 '22 10:09

jcvandan