2011-06-02 80 views
1

我保持在生產ASP.Net應用程序得到以下警告(未錯誤):收藏已修改;枚舉動作可以不執行

System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute. 
at System.Web.UI.ControlCollection.ControlCollectionEnumerator.MoveNext() 
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) 
at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) 
at System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) 
at System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) 
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) 
at DMAC.UI.Master.Render(HtmlTextWriter writer) 
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) 
at System.Web.UI.Page.Render(HtmlTextWriter writer) 
at Telerik.Web.UI.RadAjaxControl.RenderPageInAjaxMode(HtmlTextWriter writer, Control page) 
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) 
at System.Web.UI.Page.Render(HtmlTextWriter writer) 
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
--- End of inner exception stack trace --- 
at System.Web.UI.Page.HandleError(Exception e) 
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 
at System.Web.UI.Page.ProcessRequest() 
at System.Web.UI.Page.ProcessRequest(HttpContext context) 
at ASP.scan_history_aspx.ProcessRequest(HttpContext context) 
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

下面是渲染方法,其中所述錯誤發生的代碼:

protected override void Render(HtmlTextWriter writer) 
    { 
     Header header = new Header(); 
     List<Menu> menus = DMAC.Application.Current().Menus; 
     Menu menu = menus.Find(m => m.MenuId == MenuId); 

     SiteMapWindow siteWindow = new SiteMapWindow(); 
     siteWindow.OpenerId = Menu.PATHID; 
     this.Page.Form.Controls.Add(siteWindow); 

     SupportWindow supportWindow = new SupportWindow(); 
     supportWindow.OpenerId = Menu.SUPPORTID; 
     this.Page.Form.Controls.Add(supportWindow); 

     this.Page.Form.Controls.AddAt(0, menu); 
     this.Page.Form.Controls.AddAt(0, header); 

     Scripts.GoogleAnalytics.RegisterScript(this.Page); 
     base.Render(writer); 
    } 

我不能自己重新創建錯誤。有任何想法嗎?

+6

我並不總是測試我的代碼;但是當我這樣做時,我會在生產中做到這一點。 – 2011-06-02 01:27:56

+1

這沒有任何警告。 --Obi-Wan – 2011-06-02 01:29:01

+0

@Brandon,渴望我的朋友。 – Marlon 2011-06-02 01:29:19

回答

0

我懷疑問題就出現在Render

也就是說,的控件添加到這很可能是在其上迭代爲了使孩子頁面控件集合添加(非獨生子女)控制。(和我假設,其中包括該代碼;在子控件)

移動佈局的修改(實際上,在方法的所有內容)到CreateChildControls或者什麼可能是合適的。 (我不確定CreateChildControls實際上在這裏沒問題 - 我相信這個問題是Page Controls 不是的孩子。)

快樂編碼。

相關問題