System.Web.Routing.RouteCollection和System.Web.Mvc.RouteCollectionExtensions都具有相同的简单名称"IgnoreRouteInternal" [英] System.Web.Routing.RouteCollection and System.Web.Mvc.RouteCollectionExtensions both have same simple name of 'IgnoreRouteInternal'

查看:111
本文介绍了System.Web.Routing.RouteCollection和System.Web.Mvc.RouteCollectionExtensions都具有相同的简单名称"IgnoreRouteInternal"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET MVC项目,该项目近两个月都没有投入.只要我不更改任何代码,就可以在浏览器中进行调试.修改任何代码,甚至添加空格的那一刻,我都会收到此错误:

I’ve got an ASP.NET MVC project which I haven't worked on in almost two months. Debugging in a browser works fine as long as I don’t change ANY code. The moment I modify any code whatsoever, even adding whitespace, I get this error:

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,但看不到会有什么效果.我有另一个项目,它的设置类似,没有问题.

The only things I can think of is that changing the Routing settings was probably one of the last things I did before I picked this project up again, as far as I can tell everything is normal there. The other thing is that I’m using TortiseGit and bitbucket but I don’t see what effect that would have. I’ve got another project with a similar setup that has no issues.

如果我弄错了,这是我的RouteConfig.cs

In case I have made a mistake this is my 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}"
                );
        }
    }
}

我不知道如何解决这个问题,任何建议将不胜感激.

I have no idea how to resolve this, any suggestions would be much appreciated.

推荐答案

我面临类似的问题,经过三天的研究和调试,我设法解决了该错误消息,但该消息往往会产生误导,因为它只是引用System.Web.Routing.RouteCollectionSystem.Web.Mvc.RouteCollectionExtensions类,这使人们认为路由与它有关,但至少在我看来,它们没有关系.

I was facing a similar issue, after three days of investigating and debugging I managed to fix it, the error message tends to be a bit misleading, because it only refers to the System.Web.Routing.RouteCollection and the System.Web.Mvc.RouteCollectionExtensions classes, and that leads one to think routes have something to do with it, but they don't, at least in my case.

在我的情况下,我错误地将实体的导航属性声明为ICollection<Controller>,因此Entity Framework让我对要注册的类感到困惑.

In my case I mistakenly declared an entity's navigation property as ICollection<Controller>, so Entity Framework was getting all confused about the classes I wanted to register.

因此,我建议您在模型中搜索作为保留字命名的任何属性或类,或者不属于该模型的类并对其重命名.

So, I'd recommend searching your model for any property or class named as a reserved word or a class that doesn't belong to the model and rename it.

我希望对您有帮助

这篇关于System.Web.Routing.RouteCollection和System.Web.Mvc.RouteCollectionExtensions都具有相同的简单名称"IgnoreRouteInternal"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆