xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.46k stars 511 forks source link

Unable to sort because the IComparer.Compare() method returns inconsistent results #4122

Closed metaine closed 6 years ago

metaine commented 6 years ago

Steps to Reproduce

Unable to sort because the IComparer.Compare() method returns inconsistent results. Either a value does not compare equal to itself, or one value repeatedly compared to another value yields different results. IComparer: 'System.Collections.Generic.ComparisonComparer1[System.Int32]'. at System.Collections.Generic.IntrospectiveSortUtilities.ThrowOrIgnoreBadComparer (System.Object comparer) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs:36 at System.Collections.Generic.ArraySortHelper1[T].Sort (T[] keys, System.Int32 index, System.Int32 length, System.Collections.Generic.IComparer1[T] comparer) [0x00022] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Collections/Generic/ArraySortHelper.cs:62 at System.Array.Sort[T] (T[] array, System.Int32 index, System.Int32 length, System.Collections.Generic.IComparer1[T] comparer) [0x00048] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.10.1.178/src/Xamarin.iOS/external/corert/src/System.Private.CoreLib/src/System/Array.cs:1105 at System.Linq.EnumerableSorter2[TElement,TKey].QuickSort (System.Int32[] keys, System.Int32 lo, System.Int32 hi) [0x00019] in <3f40e6eb1f3746c898e4eea533aadcb6>:0 at System.Linq.EnumerableSorter1[TElement].Sort (TElement[] elements, System.Int32 count) [0x00009] in <3f40e6eb1f3746c898e4eea533aadcb6>:0 at System.Linq.OrderedEnumerable1[TElement].SortedMap (System.Linq.Buffer1[TElement] buffer) [0x00006] in <3f40e6eb1f3746c898e4eea533aadcb6>:0 at System.Linq.OrderedEnumerable1[TElement].ToList () [0x0001f] in <3f40e6eb1f3746c898e4eea533aadcb6>:0 at System.Linq.Enumerable.ToList[TSource] (System.Collections.Generic.IEnumerable1[T] source) [0x0001f] in <3f40e6eb1f3746c898e4eea533aadcb6>:0

Happens randomly on call to LINQ ToList() function on my data set. The set nature is not important here, because Exception is thrown from Xamarin.iOS ArraySortHelper when it tries to sort Integer array using generic comparer.

There is a bug in ArraySortHelper::PickPivotAndPartition causing the raise of IndexOutOfRange exception. Please see screenshot attached

scr

Expected Behavior

Should not throw exception here

Actual Behavior

Environment

Reproduced with Xamarin.iOS preview 11.11.0.280 as well as on VSMac stable channel config 11.10.1.178

=== Visual Studio Community 2017 for Mac (Preview) ===

Version 7.6 Preview (7.6 build 711)
Installation UUID: c7c52c13-ff7a-4f7e-97b8-78f989191d64
Runtime:
    Mono 5.12.0.226 (2018-02/9824e260f56) (64-bit)
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 4.4.0.36 (master / 0c7c49a6)

    Package version: 512000226

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    2.0.5
    2.0.0
SDK: /usr/local/share/dotnet/sdk/2.1.4/Sdks
SDK Versions:
    2.1.4
    2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.12.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.3
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 9.3.1 (14154.1)
Build 9E501

=== Xamarin.Mac ===

Version: 4.5.0.280 (Visual Studio Community)
Hash: e85a7be8
Branch: master
Build date: 2018-05-03 11:35:01-0400

=== Xamarin.iOS ===

Version: 11.11.0.280 (Visual Studio Community)
Hash: e85a7be8
Branch: master
Build date: 2018-05-03 11:35:00-0400

=== Xamarin.Android ===

Version: 8.3.0.19 (Visual Studio Community)
    Supported Android versions:
        6.0 (API level 23)
        7.1 (API level 25)
        8.0 (API level 26)

SDK Tools Version: 25.1.2
SDK Platform Tools Version: 24.0.0
SDK Build Tools Version: 23.0.2

Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Inspector ===

Version: 1.4.0
Hash: b3f92f9
Branch: master
Build date: Fri, 19 Jan 2018 22:00:34 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 706000711
Git revision: 634060c6c105fd3ee36678fe547680fd258cbf45
Build date: 2018-05-04 16:11:06-04
Xamarin extensions: c6720450018cb69a3da7c6d0aa0715c013783595
Build lane: monodevelop-lion-master

=== Operating System ===

Mac OS X 10.13.4
Darwin 17.5.0 Darwin Kernel Version 17.5.0
    Fri Apr 13 19:32:32 PDT 2018
    root:xnu-4570.51.2~1/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

Prism Template Pack 2.0.0
Internet of Things (IoT) development (Preview) 7.5

Build Logs

Example Project (If Possible)

Sorry, cannot provide.

VincentDondain commented 6 years ago

This issue was moved to mono/mono#8859