We have a production web site that we recently upgraded to the July 2013 release of the Ajax Control Toolkit. Since then, we're seeing an unhandled exception in the application event log. There doesn't seem to be a pattern to the error, and we only see it
about once a day even though we have hundreds of active users. We don't believe we've made any other changes that are related to this problem. It doesn't seem to be related to any other events, like recycling or time of day.
Is anyone else seeing this error?
Any idea how to troubleshoot this one?
Thanks for any ideas!
Event ID: 1309
Event code: 3005
Event message: An unhandled exception has occurred.
Exception type: InvalidOperationException
Exception message: Collection was modified; enumeration operation may not execute.
The full text of the event is shown below:
Source: ASP.NET 4.0.30319.0
Event ID: 1309
Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 8/27/2013 4:25:11 PM
Event time (UTC): 8/27/2013 8:25:11 PM
Event ID: b471019e51c94fc8b835f20803b11d23
Event sequence: 8523
Event occurrence: 19
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/2/ROOT-1-130221037256083188
Trust level: Full
Application Virtual Path: /
Application Path: C:\Users\Administrator\Documents\AdaCareWeb\
Machine name: H-ADACARE
Process information:
Process ID: 5784
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE
Exception information:
Exception type: InvalidOperationException
Exception message: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetScriptReferences(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedScriptContent(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedScriptContentHash(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManager.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Request information:
Request URL: https://my.adacare.com:443/Login.aspx?ReturnUrl=/
Request path: /Login.aspx
User host address: 96.10.192.232
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE
Thread information:
Thread ID: 40
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace: at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetScriptReferences(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedScriptContent(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedScriptContentHash(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManager.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Custom event details:
at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetScriptReferences(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedScriptContent(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedScriptContentHash(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManager.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Hello,
I’m glad to see you post the issue to asp.net forum. Based on the exception information you provided, I Think the
exception is caused by Control Bundles in a file located in AjaxControlToolkit.config which at the root of your application.
For this issue, please see the comment in the following link, where
StephenWalther has provided entire description and solution
for a similar exception with you. Please try the method mentioned in it.
Actually, I'm not using bundles, so I don't have the AjaxControlToolkit.config file in my solution. About all we did was upgrade to the July 2013 release, with no other Ajax-related changes.
Also, I'm not sure which comment in the blog you were referring me to. The error I'm seeing is "Collection was modified," not a null reference. Plus, it's an error that only appears about once a day on a busy web site.
This problem has the feel of an Ajax bug, but I don't want to jump to that conclusion. Any ideas?
I'm getting the exact same Exception, so I tried adding a bundle (with only the controls I am using) to see if this would make any difference.
At first I thought it had worked, but that turned out not to be the case, the errors are still coming.
I guess the next stage is to download the source code and try and see if I can figure out what it causing it, but the problem is that I've not had the problem myself, so could be a bit tricky.
However, I am in agreement that this would seem like a bug, given that it only appeared once the July 2013 release was installed.
I 'm getting the same Exception. But I have never had the problem either... Any help would be appreciated.
I am not using the Bundles.
InnerException: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate) at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetScriptReferences(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedScriptContent(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedScriptContentHash(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManager.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
I'm also getting the same exception after switching to ToolkitScriptManager after the last release. I then tried adding the bundles config but continue to get the error, but only a couple of times a day and on more than one page, though they share the same
MasterPage.
From looking at the source code I think the problem is that ToolkitScriptManager has a static reference to ToolkitScriptManagerCombiner, but some of the methods in ToolkitScriptCombiner, including GetScriptReferences, are not thread-safe.
Thanks for looking into the code, Stephen. The problem behaves like a threading issue, too, in that it only happens intermittently. I don't spend much time on this forum -- what's the best way to have this looked at for a possible bug fix?
I have been getting this error recently and looked into ToolkitScriptManagerCombiner as you mentioned. I did see that this code may be causing the issue:
scriptReferences = scriptReferences.Distinct().ToList();
if (addedScriptReferences != null) {
foreach (var script in addedScriptReferences) {
scriptReferences.Add(script);
}
}
if (removedScriptReferences != null) {
foreach (var script in removedScriptReferences) {
var scriptToRemove = scriptReferences.FirstOrDefault(s => s.Name.Equals(script.Name) && s.Assembly.Equals(script.Assembly));
if (scriptToRemove != null)
scriptReferences.Remove(scriptToRemove);
}
}
It may be that if addedScriptReferences or removedScriptReferences changes then the underlying list would be modified. I do not see any harm in cloning the lists so they cannot be modified and using the clones instead.
Something like this:
scriptReferences = scriptReferences.Distinct().ToList();
if (addedScriptReferences != null) {
var addedScriptReferencesClone = addedScriptReferences.ToList();
foreach (var script in addedScriptReferencesClone) {
scriptReferences.Add(script);
}
}
if (removedScriptReferences != null) {
var removedScriptReferencesClone = removedScriptReferences.ToList();
foreach (var script in removedScriptReferencesClone) {
var scriptToRemove = scriptReferences.FirstOrDefault(s => s.Name.Equals(script.Name) && s.Assembly.Equals(script.Assembly));
if (scriptToRemove != null)
scriptReferences.Remove(scriptToRemove);
}
}
Member
13 Points
23 Posts
AjaxControlToolkit error, Collection was modified; enumeration operation may not execute
Aug 27, 2013 09:16 PM|sandygettings|LINK
We have a production web site that we recently upgraded to the July 2013 release of the Ajax Control Toolkit. Since then, we're seeing an unhandled exception in the application event log. There doesn't seem to be a pattern to the error, and we only see it about once a day even though we have hundreds of active users. We don't believe we've made any other changes that are related to this problem. It doesn't seem to be related to any other events, like recycling or time of day.
Is anyone else seeing this error?
Any idea how to troubleshoot this one?
Thanks for any ideas!
Event ID: 1309
Event code: 3005
Event message: An unhandled exception has occurred.
Exception type: InvalidOperationException
Exception message: Collection was modified; enumeration operation may not execute.
The full text of the event is shown below:
AjaxControlToolkit
All-Star
30411 Points
3628 Posts
Re: AjaxControlToolkit error, Collection was modified; enumeration operation may not execute
Aug 29, 2013 04:54 AM|Fuxiang Zhang - MSFT|LINK
Hello,
I’m glad to see you post the issue to asp.net forum. Based on the exception information you provided, I Think the
exception is caused by Control Bundles in a file located in AjaxControlToolkit.config which at the root of your application.
For this issue, please see the comment in the following link, where StephenWalther has provided entire description and solution
for a similar exception with you. Please try the method mentioned in it.
http://stephenwalther.com/archive/2013/07/25/july-2013-release-of-the-ajax-control-toolkit
If I misunderstand your issue, please do not hesitate to feedback.
Best regards!
AjaxControlToolkit
Member
13 Points
23 Posts
Re: AjaxControlToolkit error, Collection was modified; enumeration operation may not execute
Aug 29, 2013 11:41 AM|sandygettings|LINK
Actually, I'm not using bundles, so I don't have the AjaxControlToolkit.config file in my solution. About all we did was upgrade to the July 2013 release, with no other Ajax-related changes.
Also, I'm not sure which comment in the blog you were referring me to. The error I'm seeing is "Collection was modified," not a null reference. Plus, it's an error that only appears about once a day on a busy web site.
This problem has the feel of an Ajax bug, but I don't want to jump to that conclusion. Any ideas?
AjaxControlToolkit
None
0 Points
1 Post
Re: AjaxControlToolkit error, Collection was modified; enumeration operation may not execute
Sep 04, 2013 04:57 AM|andy76|LINK
Hi,
I'm getting the exact same Exception, so I tried adding a bundle (with only the controls I am using) to see if this would make any difference.
At first I thought it had worked, but that turned out not to be the case, the errors are still coming.
I guess the next stage is to download the source code and try and see if I can figure out what it causing it, but the problem is that I've not had the problem myself, so could be a bit tricky.
However, I am in agreement that this would seem like a bug, given that it only appeared once the July 2013 release was installed.
AjaxControlToolkit
None
0 Points
1 Post
Re: AjaxControlToolkit error, Collection was modified; enumeration operation may not execute
Sep 04, 2013 06:03 AM|tinusd|LINK
I 'm getting the same Exception. But I have never had the problem either... Any help would be appreciated.
I am not using the Bundles.
InnerException: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Linq.Enumerable.All[TSource](IEnumerable`1 source, Func`2 predicate) at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetScriptReferences(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedScriptContent(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManagerCombiner.GetCombinedScriptContentHash(HttpContextBase context, String[] bundles)
at AjaxControlToolkit.ToolkitScriptManager.OnLoad(EventArgs e)
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
AjaxControlToolkit
None
0 Points
2 Posts
Re: AjaxControlToolkit error, Collection was modified; enumeration operation may not execute
Sep 04, 2013 12:36 PM|stephen.young|LINK
I'm also getting the same exception after switching to ToolkitScriptManager after the last release. I then tried adding the bundles config but continue to get the error, but only a couple of times a day and on more than one page, though they share the same MasterPage.
AjaxControlToolkit
None
0 Points
2 Posts
Re: AjaxControlToolkit error, Collection was modified; enumeration operation may not execute
Sep 05, 2013 04:37 PM|nuronce|LINK
Same issue here as well...Anyone solve it?
https://ajaxcontroltoolkit.codeplex.com/workitem/27516
AjaxControlToolkit
None
0 Points
2 Posts
Re: AjaxControlToolkit error, Collection was modified; enumeration operation may not execute
Sep 09, 2013 01:36 AM|stephen.young|LINK
From looking at the source code I think the problem is that ToolkitScriptManager has a static reference to ToolkitScriptManagerCombiner, but some of the methods in ToolkitScriptCombiner, including GetScriptReferences, are not thread-safe.
AjaxControlToolkit
Member
13 Points
23 Posts
Re: AjaxControlToolkit error, Collection was modified; enumeration operation may not execute
Sep 09, 2013 08:24 AM|sandygettings|LINK
Thanks for looking into the code, Stephen. The problem behaves like a threading issue, too, in that it only happens intermittently. I don't spend much time on this forum -- what's the best way to have this looked at for a possible bug fix?
AjaxControlToolkit
None
0 Points
2 Posts
Re: AjaxControlToolkit error, Collection was modified; enumeration operation may not execute
Sep 09, 2013 10:17 AM|syoungstephen|LINK
I think the best thing to do is to follow the link on nuronce's post above and vote on the issue and/or post a comment on codeplex.
AjaxControlToolkit
None
0 Points
1 Post
Re: AjaxControlToolkit error, Collection was modified; enumeration operation may not execute
Feb 27, 2014 11:28 AM|conviva|LINK
I have been getting this error recently and looked into ToolkitScriptManagerCombiner as you mentioned. I did see that this code may be causing the issue:
It may be that if addedScriptReferences or removedScriptReferences changes then the underlying list would be modified. I do not see any harm in cloning the lists so they cannot be modified and using the clones instead.
Something like this:
FWIW
AjaxControlToolkit