Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create an async Main

Tags:

c#

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

like image 843
Charanoglu Avatar asked Jul 21 '18 12:07

Charanoglu


2 Answers

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)

like image 128
BRAHIM Kamel Avatar answered Oct 17 '22 06:10

BRAHIM Kamel


Add this in your csproj.

<PropertyGroup>
    <LangVersion>latest</LangVersion>
</PropertyGroup>
like image 29
Nalan Madheswaran Avatar answered Oct 17 '22 04:10

Nalan Madheswaran