System.Web.Routing.RouteCollection和System.Web.Mvc.RouteCollectionExtensions都具有相同的简单名称'IgnoreRouteInternal'
问题描述:
我有一个ASP.NET MVC项目,我在近两个月内还没有开发过。只要我不更改任何代码,在浏览器中调试就可以正常工作。我修改任何代码无论如何,即使将空白的那一刻,我得到这个错误:System.Web.Routing.RouteCollection和System.Web.Mvc.RouteCollectionExtensions都具有相同的简单名称'IgnoreRouteInternal'
An exception of type 'System.NotSupportedException' occurred in EntityFramework.dll but was not handled in user code
Additional information: The type 'System.Web.Routing.RouteCollection+IgnoreRouteInternal' and the type 'System.Web.Mvc.RouteCollectionExtensions+IgnoreRouteInternal' both have the same simple name of 'IgnoreRouteInternal' and so cannot be used in the same model. All types in a given model must have unique simple names. Use 'NotMappedAttribute' or call Ignore in the Code First fluent API to explicitly exclude a property or type from the model.
唯一的例外发生在这条线:
var item = Cards.FirstOrDefault(s => s.name == cardName);
唯一的东西我能想到的是,改变路由设置可能是我在再次选择这个项目之前所做的最后一件事情,据我所知,在那里一切都很正常。另一件事是我正在使用TortiseGit和bitbucket,但我不知道会有什么效果。我有另一个类似的设置项目没有问题。如果我犯了一个错误,这是我的RouteConfig.cs
using System;
using System.Web.Mvc;
using System.Web.Routing;
namespace houseOfCards
{
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 }
);
routes.MapRoute(
name: "Hello",
url: "{controller}/{action}/{name}/{id}"
);
}
}
}
我不知道如何解决这个
,任何建议将不胜感激。
答
我遇到了类似的问题,经过三天的调查和调试,我设法解决它,错误信息往往有点误导,因为它只涉及System.Web.Routing.RouteCollection
和System.Web.Mvc.RouteCollectionExtensions
类,认为路线与它有关系,但他们不这样做,至少在我的情况下。
在我的情况下,我错误地宣布实体的导航属性为ICollection<Controller>
,所以Entity Framework对我想注册的类感到困惑。
因此,我建议在模型中搜索任何属性或类,这些属性或类被命名为保留字或不属于该模型的类并重新命名。
我希望它有帮助
完美的建议!出于什么原因,从控制器中产生了一些导致该问题的公共方法。删除它们解决了问题。谢谢! – Nate