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

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Sep 24 20:39:18 EDT 2007


https://bugzilla.novell.com/show_bug.cgi?id=328036

           Summary: Casting bug with generic collections
           Product: Mono: Class Libraries
           Version: 1.2
          Platform: PC
        OS/Version: Ubuntu
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: mono-bugs at ximian.com
        ReportedBy: michi at zeroc.com
         QAContact: mono-bugs at ximian.com
          Found By: Development


The code below compiles and runs fine with VS 2005 and prints "a".

With Mono 1.2.4, I get a cast exception:

Unhandled Exception: System.InvalidCastException: Cannot cast from 
source type to destination type.
  at System.Collections.Generic.Dictionary 
2+KeyColleciton[System.String,System.String].System.Collections.ICollection.CopyTo 
(System.Array , Int32 ) [0x00000]

Here is the code:

            System.Collections.Generic.Dictionary<string, string> d = 
new System.Collections.Generic.Dictionary<string, string>();
            d["a"] = "b";
            System.Collections.ICollection keys = d.Keys;
            object[] keyArray = new object[d.Count];
            keys.CopyTo(keyArray, 0);
            System.Console.WriteLine(keyArray[0]);

Cheers,

Michi.


-- 
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