[Mono-bugs] [Bug 328036] [PATCH]Casting bug with generic collections

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Sep 9 00:39:31 EDT 2008


User mono at e-tobi.net added comment

Tobias Grimm <mono at e-tobi.net> changed:

           What    |Removed                                         |Added
                 CC|                                                |mono at e-tobi.net
           Severity|Normal                                          |Major

--- Comment #12 from Tobias Grimm <mono at e-tobi.net>  2008-09-08 22:39:31 MDT ---
I'm raising severity to Major - this bug still exists in the current SVN
version after nearly a year. KeyCollection seems to have been fixed, but
ValueCollection doesn't (see below), which is a major show stopper.

I've also attached my solution to this problem, which is slightly different.


Dictionary<string, string> genericDictionary = new Dictionary<string,
genericDictionary["a"] = "x";

object[] simpleObjectArray = new object[genericDictionary.Values.Count];

// This works:
(genericDictionary.Keys as ICollection).CopyTo(simpleObjectArray, 0);

// This fails:
(genercDictionary.Values as ICollection).CopyTo(simpleObjectArray, 0);

Unhandled Exception: System.InvalidCastException: Cannot cast from source type
to destination type.
  at (wrapper managed-to-native) object:__icall_wrapper_mono_object_castclass
(System.Array array, Int32 index) [0x00000] 
  at MainClass.Main () [0x00034] in /tmp/--/test.cs:15 

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list