System.Web.Routing.RouteCollection和System.Web.Mvc.RouteColle
本文关键字:System Web Mvc RouteColle RouteCollection Routing | 更新日期: 2023-09-27 17:51:11
我有一个ASP。. NET MVC项目,我几乎两个月没有工作了。调试在浏览器工作很好,只要我不改变任何代码。一旦我修改了任何代码,甚至添加了空格,我就会得到这个错误:
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>
,所以实体框架对我想要注册的类感到困惑。
因此,我建议在您的模型中搜索任何以保留词命名的属性或类,或者不属于模型的类,并将其重命名。
希望能有所帮助