Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

A .NET container exits because the host cannot find libhostpolicy.so

Your error

A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/'.3 more lines it can show

Fix it fast

Most common cause, 1 of 3

ENTRYPOINT starts a class library instead of the app

Name the dll whose base name matches the runtimeconfig.json file in the folder.

Fix
# final stage of the Dockerfile
ENTRYPOINT ["dotnet", "MyApp.Api.dll"]
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

"The library 'libhostpolicy.so' required to execute the application was not found" means dotnet found no runtimeconfig.json naming a framework next to the dll, so it treated the app as self-contained. Run the executable project's dll, copy the whole publish folder, and publish framework-dependent inside the Dockerfile. Applies to .NET 10 and 11 images.

  • Applies to .NET 10 (LTS), .NET 11, mcr.microsoft.com/dotnet/aspnet:10.0, Docker Engine 29
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Start the image once and read the two lines the host prints under the fatal error: 'was not found' and 'did not specify a framework' lead to different causes. Then list what really sits in the app folder. Exporting a created container works even on an image that ships without a shell.

Run this first
docker run --rm my-image
docker create --name app-files my-image
docker export app-files | tar -tf - | grep -i '^app/'
docker rm app-files

Then find the line you see in this list and open its fix:

  1. 1ENTRYPOINT starts a class library instead of the appThe host says '/app/X.runtimeconfig.json' was not found, yet the listing holds a runtimeconfig.json under a different name
  2. 2The runtimeconfig.json file never reached the imageThe listing shows MyApp.dll but no runtimeconfig.json file at all
  3. 3The folder holds a self-contained build made for another operating systemThe host says the runtimeconfig.json did not specify a framework, and the folder contains hostpolicy.dll or libhostpolicy.dylib instead of libhostpolicy.so

What does the error look like?

  • A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/'.
  • Failed to run as a self-contained app.
  • The application was run as a self-contained app because '/app/MyApp.runtimeconfig.json' was not found.
  • The application was run as a self-contained app because '/app/MyApp.runtimeconfig.json' did not specify a framework.

Cause 1 of 3

ENTRYPOINT starts a class library instead of the app

You seeThe host says '/app/X.runtimeconfig.json' was not found, yet the listing holds a runtimeconfig.json under a different name

Check

dotnet reports libhostpolicy.so as missing when ENTRYPOINT names a library assembly, because the SDK writes an [appname].runtimeconfig.json only for projects that need one, such as an executable. A solution with an Api project and Core or Data libraries publishes every dll into one folder, so a wrong name in ENTRYPOINT still points at a real file. Compare the dll named in ENTRYPOINT with the runtimeconfig.json names in the listing.

Check
docker image inspect --format '{{json .Config.Entrypoint}}' my-image
docker create --name app-files my-image
docker export app-files | tar -tf - | grep -i 'runtimeconfig.json'
docker rm app-files

Fix

Name the dll whose base name matches the runtimeconfig.json file in the folder. That file belongs to the project you published, and it is the one dotnet can start.

Fix
# final stage of the Dockerfile
ENTRYPOINT ["dotnet", "MyApp.Api.dll"]

Verify

Rebuild and run the image: the app's own startup log replaces the host error.

Verify
docker build -t my-image .
docker run --rm my-image

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 3

The runtimeconfig.json file never reached the image

You seeThe listing shows MyApp.dll but no runtimeconfig.json file at all

Check

The libhostpolicy.so error also appears when the dll was copied without its runtimeconfig.json. The host reads a missing runtimeconfig.json as a self-contained app and then looks for libhostpolicy.so beside the dll. This happens when the last stage copies single files instead of the publish folder, or when prebuilt output is copied from the build context and a .dockerignore pattern such as *.json removed the file first.

Check
grep -n "COPY" Dockerfile
cat .dockerignore

Fix

Publish inside an SDK build stage and copy the whole output folder into the runtime stage, the layout Microsoft's container tutorial uses. Output made inside the build is not subject to .dockerignore.

Fix
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY . ./
RUN dotnet publish MyApp/MyApp.csproj -c Release -o /out

FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
COPY --from=build /out .
ENTRYPOINT ["dotnet", "MyApp.dll"]

Verify

The exported listing now contains MyApp.runtimeconfig.json next to MyApp.dll, and the container starts.

Verify
docker create --name app-files my-image
docker export app-files | tar -tf - | grep -i 'MyApp.runtimeconfig.json'
docker rm app-files

Confirmed by github.com

Did this fix it?

Cause 3 of 3

The folder holds a self-contained build made for another operating system

You seeThe host says the runtimeconfig.json did not specify a framework, and the folder contains hostpolicy.dll or libhostpolicy.dylib instead of libhostpolicy.so

Check

A self-contained publish carries the runtime and host files of the RID it targeted, and its runtimeconfig.json names no shared framework to load, which is what 'did not specify a framework' reports. Output published with -r win-x64 or -r osx-arm64 on a laptop and copied into a Linux image therefore brings hostpolicy.dll or libhostpolicy.dylib, and the Linux host finds no libhostpolicy.so.

Check
grep -n -E "self-contained|--runtime|-r (win|osx)-|RuntimeIdentifier" Dockerfile *.csproj
docker create --name app-files my-image
docker export app-files | tar -tf - | grep -i 'hostpolicy'
docker rm app-files

Fix

Publish inside the Linux build stage. Framework-dependent output runs on the aspnet or runtime image with dotnet. If the app must be self-contained, publish for the image's own RID (linux-x64, linux-arm64, or linux-musl-x64 for Alpine) and start the apphost directly.

Fix
# framework-dependent, started with dotnet
RUN dotnet publish MyApp/MyApp.csproj -c Release --self-contained false -o /out

# or self-contained for the image's platform, started as an executable
RUN dotnet publish MyApp/MyApp.csproj -c Release -r linux-x64 --self-contained true -o /out
ENTRYPOINT ["./MyApp"]

Verify

For a framework-dependent build the listing shows no hostpolicy file at all; for a Linux self-contained build it shows libhostpolicy.so. Either way the container starts.

Verify
docker build -t my-image .
docker run --rm my-image

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Publish in the Dockerfile's SDK stage rather than copying a bin folder from a developer machine, so the target platform always matches the image.
  • Keep the SDK and runtime images on the same .NET major, for example sdk:10.0 with aspnet:10.0.
  • Add a CI step that fails when the image has no runtimeconfig.json whose name matches the dll in ENTRYPOINT.

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 on the same stack: TaxiDex, Dispatch Pro, Raheeb.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.