带有最新更新和 ASP.NET MVC5 + 最新 Web.API 包的 Visual Studio 2013。
我收到此错误:
Multiple types were found that match the controller named 'Example'...
The request for 'Feeds' has found the following matching controllers: OldNamespace.Controllers.ExampleController and NewNamespace.Controllers.ExampleController
以前在我的项目中,我有一个名为“OldNamespace.Controllers”的命名空间,我使用“NewNamespace.Controllers”在文件中进行了查找和替换。在查找和替换之后,我清理了解决方案、重建、删除了 ASP.NET 临时文件,并对项目目录进行了全文搜索,以查找对“OldNamespace”的任何引用,但没有找到。最后,我在文件系统中搜索了任何名为“OldNamespace...”的 DLL,并删除了它们,删除了 bin 和 obj 目录并重新启动了 PC。
然而这个错误仍然发生。
最佳答案
检查这些可能的情况
尝试用新命名空间替换所有旧命名空间
如果问题仍然存在作为解决方法,请在 routeconfig 中添加命名空间,但不是确切的解决方案
公共(public)类 RouteConfig
{
公共(public)静态无效注册路由(RouteCollection 路由)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces:new string[]
{
"OldNamespace"
}
);
}
}
关于asp.net - 路由错误指的是不再存在的命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30810536/