Bug report: RuntimeBinderException: 'object' does not contain a definition for 'Task'

LinqPad 8.9.5 (x64) running on Windows.
The following script fails from time to time (I think you may have to run it once, then make some minor changes to the script, like add and remove some braces, then hit F5).

RuntimeBinderException
Message: 'object' does not contain a definition for 'Task'
StackTrace:
at CallSite.Target(Closure, CallSite, Object)
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at LINQPad.Util.CacheAsync[T](Func1 dataFetcher, String key, Boolean forceRefresh) at LINQPad.Util.CacheAsync[T](Func1 dataFetcher)
at UserQuery.Main(), line 7

async Task Main()
{
    var counts = new[] { 1, 4, 8, 2, 4 };

    var tasks = counts.Select(async c => await (new DataLoader(c)).GetSomeData());

    var sortedData = await Util.CacheAsync(async () =>

                        (await Task.WhenAll(tasks))
                            .SelectMany(x => x)
                            .OrderBy(x => x.Value)
                            .ToList()

                    );

    sortedData.Dump();  
}

class DataLoader
{
    private readonly int _count;

    public DataLoader(int count)
    {
        _count = count;
    }

    public async Task<List<Foo>> GetSomeData()
    {
        var data = new List<Foo>();
        for (var i = 0; i < _count; ++i)
        {
            data.Add(new Foo(Random.Shared.Next()));
            await Task.Delay(500);
        }
        return data;
    }
}

class Foo
{
    public Foo(int value)
    {
        Value = value;
    }

    public int Value { get; }
}

Is it better to post things like this here or use the "Help -> Report Bug" option?

Comments