Concurrency issues with ScriptManager

139 Views Asked by At

I know that Asp.Net WebForms is pretty old and obsolete, but I hope there are still people around maintaining such a legacy code base...

I'm seeing weird errors when load-testing our website, which all seem to boil down to concurrency issues in the way .Net handles the script references on the page. I can see reports of the problem dating back from 2007 here: ScriptManager throws "An entry with the same key already exists.".

I'm using .Net 4.7.2, and here is a sample of errors than occur under load:

Error 1 ArgumentException: An entry with the same key already exists.

   at System.Collections.Specialized.ListDictionary.Add(Object key, Object value)
   at System.Web.UI.ClientScriptManager.RegisterScriptBlock(ScriptKey key, String script, ListDictionary& scriptBlocks, ArrayList& scriptList, Boolean needsScriptTags)
   at System.Web.UI.ClientScriptManager.RegisterScriptBlock(ScriptKey key, String script, ClientAPIRegisterType type)
   at System.Web.UI.ScriptRegistrationManager.RegisterClientScriptInclude(Control control, Type type, String key, String url)
   at System.Web.UI.ScriptManager.RegisterClientScriptIncludeInternal(Control control, Type type, String key, String url)
   at System.Web.UI.ScriptManager.RegisterUniqueScripts(List'1 uniqueScripts)
   at System.Web.UI.ScriptManager.RegisterScripts()
   at System.Web.UI.ScriptManager.OnPagePreRenderComplete(Object sender, EventArgs e)
   at System.Web.UI.Page.OnPreRenderComplete(EventArgs e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Error 2 IndexOutOfRangeException: Index was outside the bounds of the array.

   at System.Collections.Generic.List'1.Add(T item)
   at System.Web.UI.ScriptRegistrationManager.RegisterClientScriptInclude(Control control, Type type, String key, String url)
   at System.Web.UI.ScriptManager.RegisterClientScriptIncludeInternal(Control control, Type type, String key, String url)
   at System.Web.UI.ScriptManager.RegisterUniqueScripts(List'1 uniqueScripts)
   at System.Web.UI.ScriptManager.RegisterScripts()
   at System.Web.UI.ScriptManager.OnPagePreRenderComplete(Object sender, EventArgs e)
   at System.Web.UI.Page.OnPreRenderComplete(EventArgs e)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Error 3 Object reference not set to an instance of an object.

   at System.Web.UI.ClientScriptManager.RenderRegisteredScripts(HtmlTextWriter writer, ArrayList scripts, Boolean checkForScriptManagerRegistrations)
   at System.Web.UI.ClientScriptManager.RenderClientScriptBlocks(HtmlTextWriter writer)
   at System.Web.UI.Page.BeginFormRender(HtmlTextWriter writer, String formUniqueID)
   at System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)
   at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer)
   at ASP.masters_site_master.__RenderHtml(HtmlTextWriter __w, Control parameterContainer)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
   at System.Web.UI.Page.Render(HtmlTextWriter writer)
   at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Looking at the source code from .Net, the only possibility these errors might occur is with multi-thread. I see that some fields and methods are static inside ScriptManager and ClientScriptManager which may explain this, although I haven't found a sure scenario where concurrency would occur.

Has anyone seen, solved or workaround this problem?

0

There are 0 best solutions below