Error message “CS5001 Program does not contain a static 'Main' method suitable for an entry point”

廉价感情. 提交于 2019-11-30 06:20:18

问题


Unable to execute the following code error CS5001 Program does not contain a static 'Main' method suitable for an entry point

What does this error message mean?

class Program
{
    static async Task MainAsync(string[] args)
    {
        Account.accountTest accountTest = new Account.accountTest();

        bool result = await accountTest.CreateAccountAsync();
    }
}

回答1:


It means that you don't have a suitable entry point for your application at the moment.

That code will nearly work with C# 7.1, but you do need to explicitly enable C# 7.1 in your project file:

<LangVersion>7.1</LangVersion>

or more generally:

<LangVersion>latest</LangVersion>

You also need to rename MainAsync to Main. So for example:

Program.cs:

using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        await Task.Delay(1000);
    }
}

ConsoleApp.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <LangVersion>7.1</LangVersion>
  </PropertyGroup>
</Project>

... builds and runs fine.



来源:https://stackoverflow.com/questions/47588531/error-message-cs5001-program-does-not-contain-a-static-main-method-suitable-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!