C# async Main()

Quick tip on how to solve the "Not suitable Main method" error.
June 21, 2018

C# 7.1 extended valid signatures for the static Main() method to allow the async keyword. Valid starting points of .NET applications are now:

public static void Main();
public static int Main();
public static void Main(string[] args);
public static int Main(string[] args);

public static Task Main();
public static Task<int> Main();
public static Task Main(string[] args);
public static Task<int> Main(string[] args);

Thanks to the Task return type, it’s now possible to use async/await with Main.

And now to the issue: You have to specifially select C# 7.1 or higher to enable support for async Main.

If you don’t do that, you will probably get this error message on build:

Program does not contain a static ‘Main’ method suitable for an entry point.

Solution is simple, but not obvious:

Done :)

comments powered by Disqus