https://bugzilla.novell.com/show_bug.cgi?id=444778
Summary: Dictionary<K, V> cast as ICollection puts wrong values into array in CopyTo Product: Mono: Class Libraries Version: 1.9 Platform: Other OS/Version: Other Status: NEW Severity: Normal Priority: P5 - None Component: Sys.Core AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] QAContact: mono-bugs@lists.ximian.com Found By: --- If you cast a Dictionary<K, V> to a non-generic ICollection, and then call CopyTo on that ICollection, it puts DictionaryEntry types into the array during the copy. I believe is should put KeyValuePair<K, V> types into the array. Here's an example: Dictionary<string, int> dict = new Dictionary<string, int>(); dict.Add("foo", 1); ICollection col = (ICollection) dict; foreach (object obj in col) { if (obj is KeyValuePair<string, int>) { Console.Out.WriteLine("KeyValuePair"); } } object[] arr = new object[1]; col.CopyTo(arr, 0); if (arr[0] is KeyValuePair<string, int>) { Console.Out.WriteLine("KeyValuePair"); } I would expect this to output "KeyValuePair" twice, but it only outputs it once. This seems cleary wrong. If you iterate over the collection, you get KeyValuePairs, but if you copy the collection to an array, you get something else. In the Dictionary.cs file, it's clear in the ICollection.CopyTo that it adds a new DictionaryEntry to the array. I think this should be a KeyValuePair. There's probably an opportunity for some simplification too, since then the ICollection.CopyTo implementation becomes the same as ICollection<KeyValuePair<K, V>>.CopyTo. I suspect the ICollection<KeyValuePair<K, V>>.CopyTo method could just be implemented by calling: ((ICollection)this).CopyTo(...) -- Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- You are the QA contact for the bug. _______________________________________________ mono-bugs maillist - mono-bugs@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-bugs