docker build fails with CS5001, no entry point found
error CS5001: Program does not contain a static 'Main' method suitable for an entry pointShort answer
CS5001 means the compiler built an executable project and found no entry point. In a Docker build that is usually a source file that never reached the image, a project that is meant to be a library, or two Main methods with no StartupObject. Fix the project's OutputType and entry point, then check what COPY really sent.
Fix it fast
1Find out which cause you have
Build the same project outside Docker. If it fails there too, the cause is the project. If it only fails in the image, the cause is what got copied.
dotnet build -c Release grep -n "OutputType\|StartupObject" *.csproj2Match what you see, then jump to its fix
- 1
CS5001 only inside docker build, while the same project builds on your machineThe project is an exe but no file with an entry point reached the compilerFix - 2
CS5001 after changing OutputType, or when dotnet publish runs in a folder that holds a library projectThe project you publish is a class libraryFix - 3
CS5001 or CS1558 with a Main method present in the codeThe Main method has a signature the compiler does not acceptFix - 4
CS0017: Program has more than one entry point definedTwo entry points in one projectFix
- 1
What does the error look like?
error CS5001: Program does not contain a static 'Main' method suitable for an entry pointerror CS0017: Program has more than one entry point defined.
Cause 1 of 4
The project is an exe but no file with an entry point reached the compiler
1Check
COPY can only send files that are inside the build context and not excluded by .dockerignore. A pattern that hides Program.cs, or a COPY that points at the wrong folder, leaves the compiler with no entry point. List what the image stage really contains.
cat .dockerignore
docker build --target build -t entry-check .
docker run --rm --entrypoint ls entry-check -R /src2Fix
Make sure the folder holding Program.cs is copied and not matched by .dockerignore, and that COPY paths are relative to the context root you pass to docker build.
# .dockerignore: exclude build output, not source
**/bin/
**/obj/
# Dockerfile
COPY . .
RUN dotnet publish -c Release -o /app3Verify
Rebuild the image without cache and watch the publish step finish.
docker build --no-cache -t myapp .Confirmed by docs.docker.com
Cause 2 of 4
The project you publish is a class library
1Check
A project with OutputType exe or winexe needs an entry point. A library does not. Check which project the Dockerfile publishes and what its OutputType is.
grep -n "OutputType" *.csproj
grep -n "dotnet publish\|dotnet build" Dockerfile2Fix
Publish the project that has the entry point. If a project should be a library, set its output type to Library so the compiler stops asking for Main.
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>3Verify
Publish the intended web or console project and confirm its dll is in the output folder.
dotnet publish MyApp.Web/MyApp.Web.csproj -c Release -o outConfirmed by learn.microsoft.com
Cause 3 of 4
The Main method has a signature the compiler does not accept
1Check
The entry point must be static, return void, int, Task or Task<int>, and may take a string[] parameter. The name is case-sensitive, so a method called main does not count. An async Main needs C# 7.1 or higher.
grep -rn "static.* Main\|static.* main" --include=*.cs .2Fix
Correct the signature, and move Main out of any generic type.
static async Task Main(string[] args)
{
await Task.CompletedTask;
}3Verify
Build again.
dotnet build -c ReleaseConfirmed by learn.microsoft.com
Cause 4 of 4
Two entry points in one project
1Check
A second Main, for example in a tool or sample class that was copied into the same project, makes the compiler unable to choose.
grep -rn "static.* Main(" --include=*.cs .2Fix
Remove the extra Main, or tell the compiler which type holds the real one with StartupObject. If the file uses top-level statements, remove the explicit Main instead, because the compiler ignores it.
<PropertyGroup>
<StartupObject>MyApp.Program</StartupObject>
</PropertyGroup>3Verify
Build again and confirm CS0017 is gone.
dotnet build -c ReleaseConfirmed by learn.microsoft.com
How do I stop it coming back?
- Build and publish the same project locally with the exact command from the Dockerfile before pushing.
- Keep .dockerignore limited to build output (bin and obj), logs and secrets.
- Put one explicit project path in dotnet publish when a repository holds several projects.
- Pass the context root once and keep every COPY path relative to it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
Related fixes
Servers
A containerized ASP.NET Core app says the framework Microsoft.AspNetCore.App was not found
Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
The app asks for a shared framework the final image does not have.
3 causes, each with a fixServers
docker build cannot find a local file or log in to a private NuGet feed
The parameter is incorrect
A Docker build sees only the build context, minus anything in .dockerignore, so files outside it are not found.
4 causes, each with a fixServers
ASP.NET Core container does not answer on the published port
The container is running and logs no error, but the mapped host port never answers
Since .NET 8 the ASP.NET Core container images listen on port 8080, not 80.
3 causes, each with a fixServers
MSB1011 when dotnet build or publish runs inside a Docker build
dotnet build or dotnet publish fails in a RUN step of the Dockerfile
dotnet build and dotnet publish pick a project by searching the current folder.
3 causes, each with a fixServers
dotnet says it cannot find any installed .NET SDKs (in Docker or on a server)
A compatible .NET SDK was not found
The dotnet command found a runtime but no SDK that fits.
3 causes, each with a fixServers
A .NET app throws culture errors inside a Docker container
en-us is an invalid culture identifier.
Some container images, including Alpine runtime images, ship without ICU, so .NET starts in globalization-invariant mode.
3 causes, each with a fix