我在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:
Ext.Direct.Mvc(ASP.NET MVC的Ext.Direct).该模块有一个错误(在0.8.0版本中已修复),每次为IHttpModule调用Init()时都会再次注册路由. (
which might be called multiple times).如果时机正确,它将破坏RouteTable.Routes集合,并导致上述两个例外之一.