corert icon indicating copy to clipboard operation
corert copied to clipboard

Enumerable.OrderBy does not work in reflection-free mode.

Open Thealexbarney opened this issue 5 years ago • 1 comments

Given this example code, the numbers should be printed in ascending order.

using System;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] unsorted = { 5, 257, 66, 6 };

            foreach (int val in unsorted.OrderBy(x => x))
            {
                Console.WriteLine(val);
            }
        }
    }
}

A default CoreRT build will print the sorted numbers.

5
6
66
257

However, the following is printed in reflection-free mode.

5
257
66
6

Thealexbarney avatar Sep 06 '20 03:09 Thealexbarney

I would have to debug this, but it's possibly related to the the fact that we disable the default comparers logic in reflection free mode right now.

https://github.com/dotnet/corert/blob/e3f7bb5eb143c38b6fcb3d2b772cc1bd7b4ae1f6/src/BuildIntegration/Microsoft.NETCore.Native.targets#L221-L222

Not quite sure why the fallback wouldn't work though.

Also the reasons why we had to disable them in the first place probably don't exist anymore, but enabling them will be a size regression. Comparer<Foo>.Default is basically reflection right now.

MichalStrehovsky avatar Sep 07 '20 07:09 MichalStrehovsky