After namespace change “multiple types were found that match the controller named ‘X'”

I started work on a new MVC 5 project today and after working on it for a short while I decided I wanted to change the name of the web project to [ProjectName].WebUI from just [ProjectName].  So, I renamed the project, updated the project namespace and updated all my files to use the new namespace so my solution was now made up of [ProjectName].sln, [ProjectName].WebUI and [ProjectName].WebUI.Tests.  All good I thought, but then I went to debug it and got this message:

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

I couldn’t understand what was wrong as I’d cleaned out my solution and rebuilt it without any build errors and it was only when I decided to take a look in my web project’s bin folder that I found out that the dlls that were built for the original project i.e. [ProjectName].dll were still there along with the dlls for my new project name [ProjectName].WebUI.dll.

Manually deleting the old dlls from this folder (and also from my test project folder) saved the day.

This took me a while to figure out so I’m hopeful that by writing this post it’ll maybe save someone else a bit of time (or at least save me time the next time I decide to change the name of a project after I’ve started work on it!).

Leave a Reply

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