C# "CS0017: Program has more than one entry point defined" in CI
An executable project may declare only one entry point. CS0017 fires when there are two Main methods, or top-level statements coexist with an explicit Main. It commonly appears when test/sample code is included in an exe project or files are merged into the wrong project.
What this error means
Build fails with CS0017 reporting more than one entry point. Deterministic for the source set in the project.
dotnet
error CS0017: Program has more than one entry point defined. Compile with /main to specify
the type that contains the entry point.Common causes
Two Main methods exist in the project
Two classes each declare a static Main, so the compiler cannot pick one.
Top-level statements plus an explicit Main
A file with top-level statements is an implicit entry point; adding a second Main makes two.
How to fix it
Specify the startup object
- Set
StartupObjectto the class that should be the entry point. - Rebuild.
.csproj
<PropertyGroup>
<StartupObject>MyApp.Program</StartupObject>
</PropertyGroup>Remove the extra entry point
- Delete or move the second
Main(e.g. into a separate console/test project). - Avoid mixing top-level statements with an explicit
Main. - Rebuild.
How to prevent it
- Keep one entry point per executable project.
- Put sample/alternate
Mainmethods in their own projects. - Use
StartupObjectwhen multiple candidates are intentional.
Related guides
C# "CS0246: type or namespace name could not be found" in CIFix C# "CS0246: The type or namespace name X could not be found" in CI - a missing package, project reference…
MSBuild "MSB1011: Specify which project or solution to use" in CIFix MSBuild "MSB1011: Specify which project or solution file to use" in CI - dotnet build or run found multip…
C# "CS0006: Metadata file could not be found" in CIFix C# "CS0006: Metadata file X.dll could not be found" in CI - a referenced project failed to build or built…