5

I'm trying to make the Main async, so I tried:

class Program
{
    static async Task Main(string[] args)
    {
        Books books = new Books();
        await books.AddBooksAsync();
    }
}

where AddBooksAsync have this structure:

public async Task AddBooksAsync()
{
  //some contents
}

I get this error:

Does not contain a static 'main' method suitable for an entry point

Charanoglu
  • 1,229
  • 2
  • 11
  • 30
  • Possible duplicate of [An entry point cannot be marked with the 'async' modifier](https://stackoverflow.com/questions/16712172/an-entry-point-cannot-be-marked-with-the-async-modifier) – Dennis Kuypers Jul 21 '18 at 12:47
  • Possible duplicate of [Can't specify the 'async' modifier on the 'Main' method of a console app](https://stackoverflow.com/questions/9208921/cant-specify-the-async-modifier-on-the-main-method-of-a-console-app) – SBFrancies Jul 21 '18 at 12:47
  • It compiles fine for me. Please update your question to include a screenshot of your `Advanced Build Settings` - https://learn.microsoft.com/en-us/visualstudio/ide/reference/advanced-build-settings-dialog-box-csharp . – mjwills Jul 21 '18 at 12:56

2 Answers2

17

Your visual studio by default will be setted to this enter image description here Which means that the major version will be 7.0 and not 7.1 you should force it to 7.1 in order to compile it with the 7.1 version

The second option in Project Properties=> Build =>advanced set the language version to C# latest minor version(latest)

BRAHIM Kamel
  • 13,492
  • 1
  • 36
  • 47
1

Add this in your csproj.

<PropertyGroup>
    <LangVersion>latest</LangVersion>
</PropertyGroup>
Nalan Madheswaran
  • 10,136
  • 1
  • 57
  • 42