Error E334: "await" requires the .NET 4.5 Framework, or higher

Hi
Getting odd compiler error when building following tried with 4.5 and 4.6, same error
oh, and this is on current release and latest beta

namespace AsyncDeligateTest;

interface

uses
  System.Linq, 
  System.Threading.Tasks;

type
  Program = class
  private
    class method Caller(handler: Func<Integer,Func<Task>,Task>);
  public
    class method Main(args: array of String): Int32;
  end;

implementation

class method Program.Main(args: array of String): Int32;
begin
  Caller((i,t) -> begin
    Console.WriteLine(i);
    await t;
  end);
end;

class method Program.Caller(handler: Func<Integer,Func<Task>,Task>);
begin
  handler(10, -> await Task.Delay(1000));
end;

end.

Hello Alex,

  1. please use the “Preformatted text” tool in the tool bar to format your example correctly
  2. In the Project properties, did you select .NET 4.5?
    Patrick

Thanks, logged as bugs://74410

This variant of above also gives an E0 Internal error: Object reference not set to an instance of an object

namespace AsyncDeligateTest;

interface

uses
  System.Linq, 
  System.Threading.Tasks;

type
  ITest = public interface
    method WriteAsync(s: String): Task;
  end;

  Program = class
  private
    class method Caller(handler: Func<ITest,Func<Task>,Task>);
  public
    class method Main(args: array of String): Int32;
  end;

implementation

class method Program.Main(args: array of String): Int32;
begin
  Caller((ctx,next) -> begin
    await ctx.WriteAsync('Testing');
    await next;
  end);
end;

class method Program.Caller(handler: Func<ITest,Func<Task>,Task>);
begin
  handler(nil, -> await Task.Delay(1000));
end;

end.

So the error is completely wrong, but it fails because in await t “t” is a func (delegate). If you turn it into await t() it will work.I’m fixing the error message and the NRE now.

bugs://74410 got closed with status fixed.