Skip to content

Array.Sort ( .NET 5.0 Preview 7 ) generates wrong result for a sample data set. #41235

Closed

Description

@MarcioAB

Array.Sort(sample) ( .NET 5.0 Preview 7 ) generates wrong result for a sample data set.

The sample data set is a string[] with the Namespaces for each Type in .NET.
This is 8500+ items, including a lot of nulls and repetitions.

I did a short test by modification of the current Array.Sort code in the .NET Core Source Browser.
I removed the PartitionSort part and left only the HeapSort for the entire sort.
With the HeapSort the result is correct.

Using Visual Studio 2019 version 16.8 with .NET 5.0 Preview 7.
I can provide the sample data set if that helps.

Activity

  1. svick commented on Aug 23, 2020

    @svick
    Member

    I can provide the sample data set if that helps.

    Yes, can you provide a complete example code that demonstrates the issue? Also, can you explain what makes the result wrong?

  2. MarcioAB commented on Aug 23, 2020

    @MarcioAB
    Author

    This is a simplification of the code that demonstrates the issue:

    Type[] t1 = f1();
    int max = t1.Length;
    string[] m1 = new string[max];
    for (var n = 0; n < max; n++) m1[n] = t1[n].Namespace;
    Array.Sort(m1);

    f1() is a function that extracts by reflection a list of most of the Types in the .NET (core and desktop Types).
    I can provide this function f1() but it is basically a loop in all the .NET assemblies using the function GetTypes() for each assembly.
    The attached zip contains 4 text files extracted from the Value column of the Debug (using "Copy Value")

    Sort_issue_1 contains all the 8500+ values of string[] m1 array.
    Sort_issue_2 contains all the 8500+ values of m1 after the Array.Sort(m1).
    Sort_issue_3 contains all the 8500+ values of m1 after the HeapSort(m1).
    Sort_issue_4 contains a sample of the first 500 values of Type[] t1.

    Sort_Issue.zip

    What makes the result wrong?
    Look at the file Sort_issue_2.txt, which contains the results after the sort, clearly shows there is something wrong.

  3. svick commented on Aug 23, 2020

    @svick
    Member

    You're right, it is a bug. I'm in the process of submitting a Pull Request that should fix it.

  4. Dotnet-GitSync-Bot commented on Aug 23, 2020

    @Dotnet-GitSync-Bot
    Collaborator

    I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

  5. added
    untriaged
    on Aug 23, 2020
  6. added this to the 5.0.0 milestone on Aug 23, 2020
  7. jkotas commented on Aug 23, 2020

    @jkotas
    Member

    Keep open to track release/5.0 backport

  8. reopened this on Aug 23, 2020
  9. jeffhandley commented on Aug 26, 2020

    @jeffhandley
    Member

    This was backported to release/5.0 with #41239.

  10. ghost locked as resolved and limited conversation to collaborators on Dec 7, 2020
  11. removed
    untriaged
    on Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions