Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async/await without top-level statements #63

Open
GoPapaSmurf opened this issue Apr 27, 2023 · 0 comments
Open

async/await without top-level statements #63

GoPapaSmurf opened this issue Apr 27, 2023 · 0 comments

Comments

@GoPapaSmurf
Copy link

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 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant