markjprice / cs11dotnet7

Repository for the Packt Publishing book titled "C# 11 and .NET 7 - Modern Cross-Platform Development Fundamentals" by Mark J. Price
566 stars 206 forks source link

async/await without top-level statements #63

Open GoPapaSmurf opened 1 year ago

GoPapaSmurf commented 1 year ago

Chapter: 4 Page Number: 171 Section Title: Hot reloading during development Step Number: 3 Problem to fix: The example code on p.171 raises an exception if the C# file does not use top-level statements:

while (true) {
     WriteLine("Hello, Hot Reload!");
     await Task.Delay(2000);
}

When running the code, the compiler returns: "There were build errors. Would you like to continue and run the last successful build?". Additionally, VS produces the following CS5001 error message: "Program does not contain a static 'Main' method suitable for an entry point". Suggested solution: If we want not to use top-level statements, we need to modify the Main() method:

static async Task Main(string[] args)

Other useful information e.g. OS, coding tools, and so on: Windows 10, VS 2022, VSC 1.77.3 Thank you 😉