问题
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.
The exception happens on this line:
var item = Cards.FirstOrDefault(s => s.name == cardName);
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.
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.
回答1:
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.
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.
I hope it helps
来源:https://stackoverflow.com/questions/30553883/system-web-routing-routecollection-and-system-web-mvc-routecollectionextensions