This issue wasted far too much of my time and the solution was so simple.

Problem

When I was trying to call one of my api controller methods it was saying:

Multiple types were found that match the controller named 'X'

Cause

I had made a copy of a project and renamed everything in the project

I built and ran the site, there was an error with the HomeController, saying it found 2 routes, my previous project route and my new project route.

I checked I hadn't left any reference to the previous project in there, all the namespaces were correct.

I cleaned the solution, and rebuilt loads of times.

I even changed to Guid of the project. Still that didn't fix it.

I found a suggestion online which said I should add the namespace to the MapRoute calls in the RouteConfig.cs file.

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

I also found this solution too, to help when I got an issue with OWIN

<add key="owin:appStartup" value="MyNameSpace.MyProjectName.Startup" />

These worked for the normal controllers, but it is not the right solution to the problem.

When I tried to test the rest of the site, I found I had the same issue with my API Controllers, and you can't set the namespaces in WebApiConfig.cs like you can above in the RouteConfig.cs

What was I missing? It's got to be simple. It turns out it was simple.

Solution

Clear the bin folder manually. For some reason Clean Solution didn't delete the dll for the original project from my bin folder, so it was always there causing trouble. Once I located it and delete it and it and the .pdb and .config files for it, the project worked fine.

So I've learned my lesson and I won't do it again. Hopefully you have learned your lesson too and this post has saved you a lot of time.

Paul Seal

Umbraco MVP and .NET Web Developer from Derby (UK) who specialises in building Content Management System (CMS) websites using MVC with Umbraco as a framework. Paul is passionate about web development and programming as a whole. Apart from when he's with his wife and son, if he's not writing code, he's thinking about it or listening to a podcast about it.

Proudly sponsored by

Moriyama

  • Moriyama build, support and deploy Umbraco, Azure and ASP.NET websites and applications.
AppVeyor

  • CI/CD service for Windows, Linux and macOS
  • Build, test, deploy your apps faster, on any platform.
elmah.io

  • elmah.io is the easy error logging and uptime monitoring service for .NET.
  • Take back control of your errors with support for all .NET web and logging frameworks.
uSync Complete

  • uSync.Complete gives you all the uSync packages, allowing you to completely control how your Umbraco settings, content and media is stored, transferred and managed across all your Umbraco Installations.
uSkinned

  • More than a theme for Umbraco CMS, take full control of your content and design with a feature-rich, award-nominated & content editor focused website platform.
UmbHost

  • Affordable, Geo-Redundant, Umbraco hosting which gives back to the community by sponsoring an Umbraco Open Source Developer with each hosting package sold.