Print Page | Close Window

Collection was modified; enumeration operation may not execute

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=161
Printed Date: 07-Nov-2025 at 12:04pm


Topic: Collection was modified; enumeration operation may not execute
Posted By: Customer
Subject: Collection was modified; enumeration operation may not execute
Date Posted: 12-Jul-2007 at 12:33pm

Sorry to bother you, but I have not been successful at deleting a collection of entities, I have tried variation of the following two, but all cases I get the same error. What am I doing wrong?

System.InvalidOperationException was unhandled

Message="Collection was modified; enumeration operation may not execute." 




Replies:
Posted By: IdeaBlade
Date Posted: 12-Jul-2007 at 12:33pm

You need to use "IterIsolate".  While you are iterating throught a collection, you may not modify it.  I ran into the same problem a year ago when I did the tutorial on Audit Trails.  I had a ColumnPropertyChanged Event Handler that fired while entities were being saved.  This event handler created new entities while the current set of inserted, deleted, or modified entities were being saved, thus modifying the list of saved entities.




Print Page | Close Window