[Mono-bugs] [Bug 77039][Nor] New - List<T>.Sort() thows exception
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Mon Dec 19 17:44:53 EST 2005
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by awaddell at fnfr.com.
http://bugzilla.ximian.com/show_bug.cgi?id=77039
--- shadow/77039 2005-12-19 17:44:53.000000000 -0500
+++ shadow/77039.tmp.25102 2005-12-19 17:44:53.000000000 -0500
@@ -0,0 +1,117 @@
+Bug#: 77039
+Product: Mono: Class Libraries
+Version: unspecified
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs at ximian.com
+ReportedBy: awaddell at fnfr.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: List<T>.Sort() thows exception
+
+Description of Problem: List<T> does not appear to be implementing the
+defualt Sort() method correctly.
+
+
+Steps to reproduce the problem:
+1.
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace GenericListSortBug
+{
+ class MySortableClass : IComparable<MySortableClass>
+ {
+ private int _NumberToSortOn;
+
+ public int NumberToSortOn
+ {
+ get { return _NumberToSortOn; }
+ set { _NumberToSortOn = value; }
+ }
+
+
+ public MySortableClass(int val) { _NumberToSortOn = val; }
+
+ #region IComparable<MySortableClass> Members
+
+ public int CompareTo(MySortableClass other)
+ {
+ return NumberToSortOn.CompareTo(other.NumberToSortOn);
+ }
+
+ #endregion
+ }
+
+ class Program
+ {
+ static void Main(string[] args)
+ {
+ List<MySortableClass> myList = new List<MySortableClass>();
+ MySortableClass one = new MySortableClass(1);
+ MySortableClass two = new MySortableClass(2);
+ MySortableClass three = new MySortableClass(3);
+
+ myList.Add(two);
+ myList.Add(one);
+ myList.Add(three);
+
+ myList.Sort();
+
+ foreach (MySortableClass c in myList) {
+ Console.WriteLine("Value: " + c.NumberToSortOn.ToString());
+ }
+ }
+ }
+}
+
+2.
+gmcs -target:exe -optimize- -noconfig -nowarn:1691,67
+-out:GenericListSortBug.exe -define:DEBUG -define:TRACE -define:FIXME
+-define:MONO -define:HEADLESS -define:BUGFIX_76441 -reference:System
+-reference:System.Data -reference:System.Xml
+-reference:/opt/latest/lib/mono/1.0/nunit.framework.dll Program.cs
+Properties/AssemblyInfo.cs
+3.
+[awaddell at AWLNX GenericListSortBug]$ mono GenericListSortBug.exe
+
+Actual Results:
+
+Unhandled Exception: System.InvalidOperationException: The comparer threw
+an exception. ---> System.InvalidCastException: Cannot cast from source
+type to destination type.
+in <0x0005f> System.Array:compare (System.Object value1, System.Object
+value2, IComparer comparer)
+in <0x00072> System.Array:qsort (System.Array keys, System.Array items,
+Int32 low0, Int32 high0, IComparer comparer)
+in <0x002f1> System.Array:Sort (System.Array keys, System.Array items,
+Int32 index, Int32 length, IComparer comparer)--- End of inner exception
+stack trace ---
+
+in <0x00346> System.Array:Sort (System.Array keys, System.Array items,
+Int32 index, Int32 length, IComparer comparer)
+in <0x00014> System.Array:Sort (System.Array array, Int32 index, Int32 length)
+in <0x00015>
+System.Collections.Generic.List`1[GenericListSortBug.MySortableClass]:Sort ()
+in <0x000d1> GenericListSortBug.Program:Main (System.String[] args)
+
+Expected Results:
+
+Value: 1
+Value: 2
+Value: 3
+
+
+How often does this happen?
+always
+
+
+Additional Information:
More information about the mono-bugs
mailing list