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:
- Go to your project's Properties.
- Select the Build tab.
- Click Advanced...
- Select C# version (7.1 or higher) in the Language version selector.
Done :)
Feedback
Found something inaccurate or plain wrong? Was this content helpful to you? Let me know!
š§ codez@deedx.cz