Visual Studio and .NET Framework Home
OrderedDictionary enumerator doesn't throw InvalidOperationException after collection was changed
11/25/2008 10:51:55 PM
User(s) can reproduce this bug
OrderedDictionary enumerator doesn't track the changes in the collection, so if I create an enumerator for OrderedDictionary, modify the collection and use the enumerator, InvalidOperationException is not thrown.
MSDN states the following about IEnumerator interface:
An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated and the next call to MoveNext or Reset throws an InvalidOperationException.
.NET Framework 2.0
Windows XP Professional
Operating System Language
Steps to Reproduce
static void Main()
IDictionary dictionary = new OrderedDictionary();
IEnumerator enumerator = dictionary.GetEnumerator();
dictionary["key"] = "value";
InvalidOperationException is not thrown
InvalidOperationException should be thrown
TAP Code (if applicable)
You can indicate your satisfaction with how Microsoft handled this issue by completing this quick
3 question survey
to post a comment.
Please enter a comment.
on 4/17/2009 at 4:59 PM
Thanks for reporting this issue! You're correct that OrderedDictionary's enumerator currently doesn't throw an InvalidOperationException if the collection is modified while enumerating and because of this, the OrderedDictionary enumerator doesn't comply with the IEnumerator contract.
The fix will be available in the next major release of the framework.
Base Class Libraries
on 11/26/2008 at 5:10 PM
Thanks for your feedback. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.
Visual Studio Product Team
to post a workaround.
Please enter a workaround.
© 2014 Microsoft