1

我有一個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}" 
       ); 
     } 
    } 
} 

我不知道如何解決這個

,任何建議將不勝感激。

回答

1

我遇到了類似的問題,經過三天的調查和調試,我設法解決它,錯誤信息往往有點誤導,因爲它只涉及System.Web.Routing.RouteCollectionSystem.Web.Mvc.RouteCollectionExtensions類,認爲路線與它有關係,但他們不這樣做,至少在我的情況下。

在我的情況下,我錯誤地宣佈實體的導航屬性爲ICollection<Controller>,所以Entity Framework對我想註冊的類感到困惑。

因此,我建議在模型中搜索任何屬性或類,這些屬性或類被命名爲保留字或不屬於該模型的類並重新命名。

我希望它有幫助

+0

完美的建議!出於什麼原因,從控制器中產生了一些導致該問題的公共方法。刪除它們解決了問題。謝謝! – Nate