views:

1274

answers:

3

I renamed my project from MyProjectName to MyNewProjectName. I did a complete find/replace on the solution and changed the test project aswell. In Default.aspx.cs I get an InvalidOpterationException with

"The controller name 'Home' is ambiguous between the following types: MyNewProjectName.Controllers.HomeController MyProjectName.Controllers.HomeController."

How do i fix that? Thanks

+15  A: 

Have you tried to rebuild (right click on project, and select "Rebuild")? Also check the bin to make sure only the assembly with the new name is there. Also, double check the project properties to verify the name of the assembly is outputted. If you're not sure what the name of the outputted assembly is, delete all the dlls from bin and rebuild.

John Sheehan
I did a rebuild and even a clean. I did a windows file search and apparently, VS didn't clear everything out.
Daniel A. White
This is annoying -- I just had the same issue. What a PITA. What is "clean" supposed to be doing???
Andrew Flanagan
I guess it removed files with project name, not all dlls.
Daniel A. White
+3  A: 

You need to check your /bin folder in your MVC Web project, and either delete everything inside there and do a new build, or delete the old DLL (MyProjectName.dll).

The ASP.Net MVC runtime uses reflection to determine which controller a request must be passed to based on the routing information, and it is finding two Controllers that match the criteria (have the same name), and each is in a different assembly. That is why you get the exception.

Doing a Clean doesn't seem to clear out the bin folder. So you have to delete the file manually.

Saajid Ismail
It's the old assemblies in the bin. Good call. +1
KP
Thanks.. nothing teaches better than hard-earned experience..
Saajid Ismail
A: 

Double click or right click on MyProject and open. In the application settings change the assembly name and root namespace to match your renamed project name.

RameshK