[Mono-bugs] [Bug 403882] New: PropertyDescriptorCollection.Sort() fails

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Jun 25 15:03:04 EDT 2008


           Summary: PropertyDescriptorCollection.Sort() fails
           Product: Mono: Class Libraries
           Version: SVN
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: System
        AssignedTo: contact at i-nz.net
        ReportedBy: andyhume32 at yahoo.co.uk
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

PropertyDescriptorCollection.Sort() fails

The following fails at the PropertyDescriptorCollection.Sort() line --
exception at bottom.  Does it needs internally to use a comparer like the
sample one?

using System;
using System.ComponentModel;

class PropertyDescriptorCollection_Sort {
    static void Main()

        //Type interfaceBase = typeof (IDisposable).BaseType;
        //Console.WriteLine ("[typeof(IDisposable).BaseType: {0}]", 
        //    interfaceBase == null ? "(null)" : interfaceBase.ToString());
        PropertyDescriptorCollection coll = TypeDescriptor.GetProperties (
            // bug 403880 --> typeof (IComponent)); //IBindingList));  
            typeof (Component)
        Dump (coll);
        PropertyDescriptorCollection sortedMyComparer = coll.Sort (new
PdcComparer ());
        Dump (sortedMyComparer);
        PropertyDescriptorCollection sorted = coll.Sort ();
        Dump (sorted);

    class PdcComparer : System.Collections.IComparer {
        int System.Collections.IComparer.Compare (object x, object y)
            return String.CompareOrdinal (((PropertyDescriptor)x).Name,

    static void Dump(PropertyDescriptorCollection coll)
        foreach (PropertyDescriptor cur in coll) {
            Console.Write("{0}, ", cur.Name);


Unhandled Exception: System.InvalidOperationException: The comparer threw an
exception. ---> System.InvalidCastException: Cannot cast from source type to
destination type.
 at System.Array.compare (System.Object value1, System.Object value2, IComparer
comparer) [0x00000] 
 at System.Array.qsort (System.Array keys, System.Array items, Int32 low0,
Int32 high0, IComparer comparer) [0x00000] 
 at System.Array.Sort (System.Array keys, System.Array items, Int32 index,
Int32 length, IComparer comparer) [0x00000] 
 --- End of inner exception stack trace ---
 at System.Array.Sort (System.Array keys, System.Array items, Int32 index,
Int32 length, IComparer comparer) [0x00000] 
 at System.Array.Sort (System.Array array, Int32 index, Int32 length, IComparer
comparer) [0x00000] 
 at System.Collections.ArrayList.Sort (IComparer comparer) [0x00000] 
 at System.ComponentModel.PropertyDescriptorCollection.InternalSort (IComparer
ic) [0x00000] 
 at System.ComponentModel.PropertyDescriptorCollection.Sort () [0x00000] 
 at PropertyDescriptorCollection_Sort.Main () [0x00000] 

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

More information about the mono-bugs mailing list