Last active
August 29, 2015 14:20
-
-
Save svick/8c2696222800aa031450 to your computer and use it in GitHub Desktop.
It's not safe to call ToList on IsReadOnly collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cdict = new ConcurrentDictionary<int, int>(); | |
var t = Task.Run(() => { | |
for (int i = 0; i < 100000; i++) | |
cdict[i] = i; | |
}); | |
IEnumerable<KeyValuePair<int, int>> kvps = new ReadOnlyDictionary<int, int>(cdict); | |
((ICollection<KeyValuePair<int, int>>)kvps).IsReadOnly.Dump(); // true | |
while (!t.IsCompleted) | |
kvps.ToList(); // almost always throws ArgumentException in CopyTo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment