[Mono-bugs] [Bug 76361][Nor] New - generic List.Sort(IComparer<T>) should not expect argument as IComparer

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri Oct 7 08:41:33 EDT 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 atsushi at ximian.com.

http://bugzilla.ximian.com/show_bug.cgi?id=76361

--- shadow/76361	2005-10-07 08:41:33.000000000 -0400
+++ shadow/76361.tmp.19763	2005-10-07 08:41:33.000000000 -0400
@@ -0,0 +1,63 @@
+Bug#: 76361
+Product: Mono: Class Libraries
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs at ximian.com                            
+ReportedBy: atsushi at ximian.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: generic List.Sort(IComparer<T>) should not expect argument as IComparer
+
+System.Collections.Generic.List<T>.Sort(IComparer<T>) incorrectly expects
+argument as castable to IComparer (non-generic one).
+
+Compile and run the repro code below:
+
+using System;
+using  System.Collections.Generic;
+
+public class TestComparer : IComparer<string>
+{
+        public int Compare (string s1, string s2)
+        {
+                return String.CompareOrdinal (s1, s2);
+        }
+
+        public static void Main ()
+        {
+                TestComparer t = new TestComparer ();
+                List<string> l = new List<string> ();
+                l.Add ("foo");
+                l.Add ("bar");
+                l.Sort (new TestComparer ());
+        }
+}
+
+
+Actual Results:
+
+Unhandled Exception: System.InvalidCastException: Cannot cast from source
+type to destination type.
+in <0x0002f> System.Collections.Generic.List`1[System.String]:Sort
+(IComparer`1)
+in <0x00072> TestComparer:Main ()
+
+Expected Results:
+
+no error.
+
+How often does this happen? 
+
+consistently.
+
+Additional Information:
+
+Similar problem seems to happen on bug #75625.


More information about the mono-bugs mailing list