I added a new class to my project and got an error saying “Program.Main() has more than one entry”. Why?

I experienced this issue after adding an xUnit test class to my .NET Core 2.1 project.

The following article gives a detailed explanation of why, and provided the answer that worked for me – here.

Basically, the compiler automatically generates a Main for the new class. You can provide a directive in your .csproj file to keep this from happening:

<GenerateProgramFile>false</GenerateProgramFile>

Add this to your <PropertyGroup> section and recompile.

Leave a Comment