sdk icon indicating copy to clipboard operation
sdk copied to clipboard

A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/'.

Open avifatal opened this issue 7 years ago • 19 comments

Hi, I am getting the following error when deploying donet core 3.0 with docker: A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/app/'.

This is my Dockerfile: ` FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS base WORKDIR /app EXPOSE 8080

FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS build WORKDIR /src COPY ["TestCloudRun.csproj", "TestCloudRun/"] RUN dotnet restore "TestCloudRun/TestCloudRun.csproj" COPY . . WORKDIR "/src/TestCloudRun" RUN dotnet build "TestCloudRun.csproj" -c Release -o /app/build

FROM build AS publish RUN dotnet publish "TestCloudRun.csproj" -c Release -o /app/publish

FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "TestCloudRun.dll"] ` This is the repo: https://github.com/avifatal/core3deployment-issue

I should mention that I'm deploying to google cloud run.

Thanks

avifatal avatar Nov 19 '19 19:11 avifatal

You have

<OutputType>Library</OutputType>

in your project file, but it has to be

<OutputType>Exe</OutputType>

andrii-litvinov avatar Jan 20 '20 11:01 andrii-litvinov

with ENTRYPOINT ["dotnet", "TestCloudRun.dll"], shouldn't it be a library? EXE doesn't even make sense for Linux.

NArnott avatar Jun 24 '20 16:06 NArnott

Same issue for my web app in .net core 3.1 app

SrushtiPasari-GEP avatar Jul 22 '20 10:07 SrushtiPasari-GEP

I am facing same issue with .net core app using below base image.

FROM mcr.microsoft.com/dotnet/core/runtime:2.1-stretch-slim AS base FROM mcr.microsoft.com/dotnet/core/sdk:2.1-stretch AS build

himanshuladola avatar Aug 21 '20 08:08 himanshuladola

the same issue here when running on a linux machine (ubuntu 20.04) from a docker container. FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-focal

magomedov avatar Oct 09 '20 18:10 magomedov

same problem on docker for windows (linux container) for self contrained .net core 3.1 app

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1

DMDTT avatar Dec 02 '20 12:12 DMDTT

No news about this one? any temporary workaround?

pacorreia avatar Jan 12 '21 12:01 pacorreia

For us, I think it ended up being because we had the following in our csproj, as it was built for windows before converting to Docker.

<RuntimeIdentifier>win7-x64</RuntimeIdentifier>

We just had to remove it. We ended up with basically this, which worked, while still using the DLL as the entrypoint in the Dockerfile.

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
  </PropertyGroup>
ENTRYPOINT ["dotnet", "TestCloudRun.dll"]

NArnott avatar Jan 12 '21 15:01 NArnott

Same for me

It works on Windows and Ubuntu in WSL 2, but does not work on MacOS latest on M1

 <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <RuntimeIdentifier>linux-musl-x64</RuntimeIdentifier>
    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
    <PublishTrimmed>true</PublishTrimmed>
    <PublishReadyToRun>true</PublishReadyToRun>
  </PropertyGroup>

Error:

Failed to load /app/libhostpolicy.so, error: Error relocating /app/libhostpolicy.so: unsupported relocation type 7
An error occurred while loading required library libhostpolicy.so from [/app/]
Failed to load /app/libhostpolicy.so, error: Error relocating /app/libhostpolicy.so: unsupported relocation type 7
An error occurred while loading required library libhostpolicy.so from [/app/]

So it does not work only in docker on MacOS M1.

We are using aspnet:6.0-alpine3.17 Alpine images

vitalybibikov avatar Jan 26 '23 12:01 vitalybibikov

Same for me

It works on Windows and Ubuntu in WSL 2, but does not work on MacOS latest on M1

 <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <RuntimeIdentifier>linux-musl-x64</RuntimeIdentifier>
    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
    <PublishTrimmed>true</PublishTrimmed>
    <PublishReadyToRun>true</PublishReadyToRun>
  </PropertyGroup>

Error:

Failed to load /app/libhostpolicy.so, error: Error relocating /app/libhostpolicy.so: unsupported relocation type 7
An error occurred while loading required library libhostpolicy.so from [/app/]
Failed to load /app/libhostpolicy.so, error: Error relocating /app/libhostpolicy.so: unsupported relocation type 7
An error occurred while loading required library libhostpolicy.so from [/app/]

So it does not work only in docker on MacOS M1.

We are using aspnet:6.0-alpine3.17 Alpine images

Any update from this. It does not work for me to. Note: I'm using MacOS M1!

hoangpn256 avatar Apr 12 '23 14:04 hoangpn256

Brand new virgin Blazor template throwing this error. I am using Kubuntu

wgrs avatar Jul 08 '23 17:07 wgrs

Is this dotnet only? I normally compile my C# programs with

csc -out:"./bin/Program.exe" Program.cs Helper.cs

But when I run netcoredbg I get

A fatal error was encountered. The library 'libhostpolicy.so' required to execute the application was not found in '/home/zeioth/.local/share/nvim/lazy/compiler.nvim/tests/examples/cs/build/bin/'.\nFailed to run as a self-contained app.\n  - The application was run as a self-contained app because '/home/zeioth/.local/share/nvim/lazy/compiler.nvim/tests/examples/cs/build/bin/Program.runtimeconfig.json' was not found.\n  - If this should be a framework-dependent app, add the '/home/zeioth/.local/share/nvim/lazy/compiler.nvim/tests/examples/cs/build/bin/Program.runtimeconfig.json' file and specify the appropriate framework.

But I'm not sure what to put on my runtimeconfig.json or where to find the docs about it. Do you have some example? I'm on linux.

Edit: Ok I managed. But it is quite a pain you have to hardcore the version in the runtimeconfig.json, I cannot distribute the file that way.

Zeioth avatar Jul 31 '23 20:07 Zeioth

I'm facing a similar error, I've already deployed it to a folder and pasted the files into /var/apps/projecs and when executing the dotnet project.dll command it gives the following error

Failed to load /var/apps/control-of-printers/libhostpolicy.so, error: /var/apps/control-of-printers/libhostpolicy.so: cannot open shared object file: No such file or directory An error occurred while loading required library libhostpolicy.so from [/var/apps/control-of-printers/]

ANDREOGP33 avatar Jan 30 '24 12:01 ANDREOGP33

I am facing same issues, here the project file of the Web project:

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UserSecretsId>aa193207-78b8-45d6-aa17-725e3bd9939f</UserSecretsId>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <OutputType>Library</OutputType>
    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
	  
  </PropertyGroup>

I am using docker-compose, btw

smoms avatar Jan 31 '24 22:01 smoms

I have this error without docker using. It happened after I set the Output folder for all projects in the solution to the same (common) folder.

Rombersoft avatar Mar 19 '24 10:03 Rombersoft

Same for me

It works on Windows and Ubuntu in WSL 2, but does not work on MacOS latest on M1

 <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <RuntimeIdentifier>linux-musl-x64</RuntimeIdentifier>
    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
    <PublishTrimmed>true</PublishTrimmed>
    <PublishReadyToRun>true</PublishReadyToRun>
  </PropertyGroup>

Error:

Failed to load /app/libhostpolicy.so, error: Error relocating /app/libhostpolicy.so: unsupported relocation type 7
An error occurred while loading required library libhostpolicy.so from [/app/]
Failed to load /app/libhostpolicy.so, error: Error relocating /app/libhostpolicy.so: unsupported relocation type 7
An error occurred while loading required library libhostpolicy.so from [/app/]

So it does not work only in docker on MacOS M1.

We are using aspnet:6.0-alpine3.17 Alpine images

Did you get anywhere @hoangpn256? I'm on an Apple Silicon mac also

TheAdamGalloway avatar Apr 04 '24 23:04 TheAdamGalloway

In my case my project was build for two target frameworks with net48 OutputPath "bin" and net8.0 OutputPath "bin_dotnet". When I tried debugging with WSL, it tried to start the dll from "bin" instead of "bin_dotnet". I could fix it by deleting the csproj.user file

simonegli8 avatar Apr 18 '24 10:04 simonegli8

Same for me It works on Windows and Ubuntu in WSL 2, but does not work on MacOS latest on M1

 <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <RuntimeIdentifier>linux-musl-x64</RuntimeIdentifier>
    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
    <PublishTrimmed>true</PublishTrimmed>
    <PublishReadyToRun>true</PublishReadyToRun>
  </PropertyGroup>

Error:

Failed to load /app/libhostpolicy.so, error: Error relocating /app/libhostpolicy.so: unsupported relocation type 7
An error occurred while loading required library libhostpolicy.so from [/app/]
Failed to load /app/libhostpolicy.so, error: Error relocating /app/libhostpolicy.so: unsupported relocation type 7
An error occurred while loading required library libhostpolicy.so from [/app/]

So it does not work only in docker on MacOS M1. We are using aspnet:6.0-alpine3.17 Alpine images

Any update from this. It does not work for me to. Note: I'm using MacOS M1!

I'm also working on MacOS M1, and solved this issue by changing linux-x64 to linux-arm64 in this line of docker file

RUN dotnet publish -r linux-arm64 -c Release -o out

hope this able to work with you also

DevMahmoud10 avatar Jan 16 '25 13:01 DevMahmoud10

你好,我在debian中运行dotnet *.dll文件遇到了同样的情况,我使用的是linux-arm64 Image

ifanmy avatar Mar 03 '25 03:03 ifanmy