Sdk: Program does not contain a static 'Main' method suitable for an entry point

Created on 7 Jul 2017  路  11Comments  路  Source: dotnet/sdk

Hi,

I have a netcoreapp2.0 project that failed to build with the following error when I tried to build it with dotnet build:

CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point

Then I open the project in Visual Studio (d15prerel 26629.02), the project built fine in VS, and after that the error is gone from 'dotnet build' and it succeeds.

After I run 'dotnet clean', 'dotnet build' starts failing with the same error

Here is my project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
    <!-- omitted AssemblyName and RootNamespace properties -->
    <LangVersion>Latest</LangVersion>
    <PackageTargetFallback>$(PackageTargetFallback);portable-net40+sl5+win8+wp8+wpa81;portable-net45+win8+wp8+wpa81</PackageTargetFallback>
  </PropertyGroup>

  <ItemGroup>
    <!-- some project references to other projects -->
  </ItemGroup>

</Project>

There is only one Program.cs file in the project, it has this entry point:

namespace ...
{
    static class Program
    {
...
        public static async Task Main(string[] args)
        {
        }
...

Most helpful comment

Try replacing <LangVersion>Latest</LangVersion> with <LangVersion>7.1</LangVersion>

All 11 comments

The issue doesn't repro in dotnet SDK 2.0.0-preview2-006497

Hi @IlyaBiryukov What is the version you are having problem?

Since async Main is a brand-new C# 7.1 feature, I'd guess that an old Roslyn compiler is involved in the problem cases, and a newer one is used for the success cases. But it's not clear to me why different compilers would be found either way.

I was having this problem with dotnet SDK 2.0.0-preview1-005842.
It doesn't repro with 2.0.0-preview2-006497

Correct. You need a new version of Roslyn that supports the feature. We have that now in preview2. @rainersigwald what is your confusion? Each version of the CLI ships with its own copy of roslyn.

@livarcocc My confusion was:

the project built fine in VS, and after that the error is gone from 'dotnet build' and it succeeds.

But that could be explained by incremental build kicking in, so the subsequent dotnet build invocations didn't invoke the compiler.

Try replacing <LangVersion>Latest</LangVersion> with <LangVersion>7.1</LangVersion>

same issue happened to me but after i added a class and deleted it (it was working perfect before the class)

Same issue here!

Same issue here! in 3.1

Facing same issue in netcoreapp3.1 also. Upon googling, found that it is because i am using async on Main method in Program.cs file. Did not succeed even defined LangVersion in csproj file.

<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

Tried 7.1 too.

Was this page helpful?
0 / 5 - 0 ratings