Coder Perfect

There are several varieties that match the ‘Home’ controller.

Problem

I currently have two MVC3 projects available that are unconnected.

One works perfectly, but the other does not, resulting in the following error:

My hoster provides me with FTP access to a folder in which I have two other folders, one for each of my programs.

It works with foo.com since I publish my program to my local file system and then FTP the contents.

When I upload and try to run bar.com, the problem described above occurs, preventing me from using my site. All while foo.com continues to function normally.

Is bar.com looking for controllers EVERYWHERE in ftpFolderA2 and discovering another HomeController as a result? How can I instruct it to look exclusively in the Controller folder, as it should?

Facts:

Can anyone confirm that this is the issue?

Asked by Only Bolivian Here

Solution #1

Another scenario in which you might get this problem is as follows. If you rename your project so that the assembly’s file name changes, you may end up with two copies of your ASP.NET assembly, both of which will reproduce the problem.

The solution is to delete the old dlls from your bin folder. (I tried “Rebuild Project,” but it didn’t work, so double-check the bin to make sure they’re gone.)

Answered by Kirk Woll

Solution #2

This error notice appears frequently when you use areas and the controller names inside the area and the root are the same. For instance, consider the following:

You might use namespaces when declaring your routes to solve this problem (like the error notice indicates). As a result, in Global.asax, in the primary route definition:

routes.MapRoute(
    "Default",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = UrlParameter.Optional },
    new[] { "AppName.Controllers" }
);

/Areas/Admin/AdminAreaRegistration.cs and /Areas/Admin/AdminAreaRegistration.cs

context.MapRoute(
    "Admin_default",
    "Admin/{controller}/{action}/{id}",
    new { action = "Index", id = UrlParameter.Optional },
    new[] { "AppName.Areas.Admin.Controllers" }
);

If you don’t use areas, your two applications appear to be hosted within the same ASP.NET application, and conflicts arise since the identical controllers are defined in different namespaces. If you want to avoid conflicts, you’ll need to setup IIS to host those two as different ASP.NET applications. If you don’t have access to the server, ask your hosting provider for help.

Answered by Darin Dimitrov

Solution #3

It’s a little different in MVC4 and MVC5, therefore use the following.

/App_Start/RouteConfig.cs

namespace MyNamespace
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

and in Areas

context.MapRoute(
                "Admin_default",
                "Admin/{controller}/{action}/{id}",
                new { action = "Index", id = UrlParameter.Optional },
                new[] { "MyNamespace.Areas.Admin.Controllers" }
            );

Answered by Developer

Solution #4

Watch this… http://www.asp.net/mvc/videos/mvc-2/how-do-i/aspnet-mvc-2-areas

Then there’s this image (hope u like my drawings)

Answered by Tom

Solution #5

in your project folder/bin

Ensure that just your PROJECT PACKAGENAME.DLL is installed.

and remove ANOTHER_PROJECT_PACKAGENAME.DLL

That may have appeared here by accident, or you may have simply renamed your project.

Answered by Sruit A.Suk

Post is based on https://stackoverflow.com/questions/7842293/multiple-types-were-found-that-match-the-controller-named-home