Multiple types were found that match the controlle

2019-01-03 20:17发布

I currently have two unrelated MVC3 projects hosted online.

One works fine, the other doesn't work, giving me the error:

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.

The way my hoster works is that he gives me FTP access and in that folder I have two other folder, one for each of my applications.

ftpFolderA2/foo.com

ftpFolderA2/bar.com

foo.com works fine, I publish my application to my local file system then FTP the contents and it works.

When I upload and try to run bar.com, the issue above fires and prevents me from using my site. All while foo.com still works.

Is bar.com searching from controllers EVERYWHERE inside of ftpFolderA2 and that's why it's finding another HomeController? How can I tell it to only look in the Controller folder as it should?

Facts:

  1. Not using areas. These are two COMPLETELY unrelated projects. I place each published project into each respective folder. Nothing fancy.
  2. Each project only has 1 HomeController.

Can someone confirm this is the problem?

24条回答
Viruses.
2楼-- · 2019-01-03 20:44

Here is another scenario where you might confront this error. If you rename your project so that the file name of the assembly changes, it's possible for you to have two versions of your ASP.NET assembly, which will reproduce this error.

The solution is to go to your bin folder and delete the old dlls. (I tried "Rebuild Project", but that didn't delete 'em, so do make sure to check bin to ensure they're gone)

查看更多
祖国的老花朵
3楼-- · 2019-01-03 20:45

in your project bin/ folder

make sure that you have only your PROJECT_PACKAGENAME.DLL

and remove ANOTHER_PROJECT_PACKAGENAME.DLL

that might appear here by mistake or you just rename your project

查看更多
贼婆χ
4楼-- · 2019-01-03 20:46

i just deleted folder 'Bin' from server and copy my bin to server, and my problem solved.

查看更多
别忘想泡老子
5楼-- · 2019-01-03 20:47

If it could help other, I've also face this error. The problem was cause by on incorrect reference in me web site. For unknown reason my web site was referring another web site, in the same solution. And once I remove that bad reference, thing began to work properly.

查看更多
\"骚年 ilove
6楼-- · 2019-01-03 20:48

There might be another case with Areas even you have followed all steps in routing in Areas(like giving Namespaces in global routing table), which is:

You might not have wrapped your Global Controller(s) in 'namespace' you provided in routing.

Eg:

Done this:

public class HomeController : Controller
{

Instead of:

namespace GivenNamespace.Controllers
{
   public class HomeController : Controller
   {
查看更多
家丑人穷心不美
7楼-- · 2019-01-03 20:48

Right click the project and select clean the project. Or else completely empty the bin directory and then re-build again. This should clear of any left over assemblies from previous builds

查看更多
登录 后发表回答