Multiple Controllers Found with the Name ‘HomeController’

I’ve been playing with Billy McCafferty’s S#arpArchitecture. I decided to strip the Northwind references out of the sample so I could try the framework on my own project. After removing the Northwind-specific files and renaming the remaining files and namespaces to “MyProject,” I kept getting this error when I started the application:  “Multiple controllers found with the name ‘HomeController'”: 


 
Sometimes I would instead get a message that no HomeController could be found.

The Controllers project contains one (and only one) HomeController class. If I comment out that class, the project starts fine:  the home page appears as expected. There are no other occurrences of “HomeController” anywhere in the solution–so where is the HomeController that is actually running to display the home page?

The Solution 

With the help of Billy McAfferty in the CodePlex forum, I discovered that there were several instances of Northwind-related DLLs and other files hanging about in various bin and Debug folders, especially in the MyProject.Web\bin folder:

MyProject.Controllers\obj\Debug\Northwind.Controllers.csproj.FileListAbsolute.txt
MyProject.Core\obj\Debug\Northwind.Core.csproj.FileListAbsolute.txt
MyProject.Data\obj\Debug\Northwind.Data.csproj.FileListAbsolute.txt
MyProject.Tests\obj\Debug\Northwind.Tests.csproj.FileListAbsolute.txt
MyProject.Web\bin\Northwind.Controllers.dll
MyProject.Web\bin\Northwind.Controllers.pdb
MyProject.Web\bin\Northwind.Core.dll
MyProject.Web\bin\Northwind.Core.pdb
MyProject.Web\bin\Northwind.Data.dll
MyProject.Web\bin\Northwind.Data.pdb
MyProject.Web\bin\Northwind.Web.dll
MyProject.Web\bin\Northwind.Web.pdb
MyProject.Web\obj\Debug\Northwind.Web.csproj.FileListAbsolute.txt
MyProject.Web\obj\Debug\Northwind.Web.dll
MyProject.Web\obj\Debug\Northwind.Web.pdb

I deleted those files, reran the project, and voilà! I’m back to only one HomeController. (I set a breakpoint in my HomeController class just to be sure it is getting there.) Now the default page appears as expected. Just to be safe, I then followed Billy’s suggestion to delete all the bin and obj folders and then do a full rebuild:  yep, still works! Thanks Billy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.

This site uses Akismet to reduce spam. Learn how your comment data is processed.