c# – System.Web.Routing.RouteCollection.GetRouteData中的异常

前端之家收集整理的这篇文章主要介绍了c# – System.Web.Routing.RouteCollection.GetRouteData中的异常前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在iis7上运行的asp.net mvc代码随机获得了两个异常:
Exception type: InvalidOperationException 
Exception message: Collection was modified; enumeration operation may not execute. 
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.List'1.Enumerator.MoveNextRare()
   at System.Collections.Generic.List'1.Enumerator.MoveNext()
   at System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext)
   at System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context)
   at System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender,EventArgs e)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,Boolean& completedSynchronously)

Exception type: NullReferenceException 
Exception message: Object reference not set to an instance of an object. 
   at System.Web.Routing.RouteCollection.GetRouteData(HttpContextBase httpContext)
   at System.Web.Routing.UrlRoutingModule.PostResolveRequestCache(HttpContextBase context)
   at System.Web.Routing.UrlRoutingModule.OnApplicationPostResolveRequestCache(Object sender,Boolean& completedSynchronously)

它不是一贯可重复的,但我认为这是改变(或腐败)RouteTable.Routes的东西.我在项目中访问RouteTable.Routes的唯一地方是Global.asax.cs,我知道那里的代码只被调用一次,所以这不是问题所在.有关如何追踪它的任何想法?

解决方法

在我的例子中,它最终成为HttpModule: @L_403_0@(ASP.NET MVC的Ext.Direct).该模块有一个错误(在0.8.0版本中已修复),每次为IHttpModule调用Init()时都会再次注册路由. ( which might be called multiple times).如果时机正确,它将破坏RouteTable.Routes集合,并导致上述两个例外之一.
原文链接:https://www.f2er.com/csharp/244310.html

猜你在找的C#相关文章