Skip to content
Latchkey

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

  1. Set StartupObject to the class that should be the entry point.
  2. Rebuild.
.csproj
<PropertyGroup>
  <StartupObject>MyApp.Program</StartupObject>
</PropertyGroup>

Remove the extra entry point

  1. Delete or move the second Main (e.g. into a separate console/test project).
  2. Avoid mixing top-level statements with an explicit Main.
  3. Rebuild.

How to prevent it

  • Keep one entry point per executable project.
  • Put sample/alternate Main methods in their own projects.
  • Use StartupObject when multiple candidates are intentional.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →