Collection was modified; enumeration operation may not execute.

Collection was modified; enumeration operation may not execute.

Old forum URL: forums.lhotka.net/forums/t/7534.aspx


Wbmstrmjb posted on Friday, August 28, 2009

There are a couple of threads regarding this issue, but most pertain to Silverlight and CSLA 3.6+.

We are using CSLA 2.1.4 and are getting the same error intermittently when using remoting. This error never comes up locally, but sometimes comes up in our 3-tier deployment.

The error seems to occur on an Insert of a list item while the list is looping through it's children in the Update. When child.Insert is called, the next loop is throwing the error (presumably because the list has been modified?).

Is it the list (this) that is being modified and causing the error, or is something to do with Validation that is causing the error and just happens to be a list also? Or something completely different? Thanks.

Here is the top of the stack trace:

[DataPortalException: DataPortal.Update failed (System.InvalidOperationException: 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 Cap.BusinessObjects.Application.DenialDeficiencyReasonList.Update(OracleConnection cn, IApplication parent) in *****
at Cap.BusinessObjects.Application.VRApplication.UpdateChildren(OracleConnection cn) in *****
at Cap.BusinessObjects.Application.VRApplication.DataPortal_Update() in *****)]

Wbmstrmjb replied on Friday, August 28, 2009

We moved to 3.0.5 and it's not a problem now. Still would like to know why it was an issue before.

Copyright (c) Marimer LLC