I have a simple .NET Core project (console app) that I\'m trying to compile and run. dotnet build
succeeds, but I get the following error when I do dotnet
If I'm not mistaken, one scenario when you can hit the issue is this: You have an integration project that references another application project (not library). In this case, dependentProject.runtimeconfig.json
won't be copied to your integration project's output folder and you won't be able to run dependentProject.exe
binary because it will throw The library hostpolicy.dll was not found.
.
There is a Github issue for this and a workaround.
I'm not sure why but I ran in to the problem when executing the .exe file in my \bin folder while the .exe in my \obj folder works fine.
I am having this problem in Dotnet Core 3.1 Console application.
If you are publishing your application, make sure that your target runtime set to the specific runtime that you had installed in your target machine.
If you set to portable it will pick whatever runtime that it feels comfortable (which you might not have it installed)
In my case it was because I was publishing a self-contained application for the wrong target. My intent was to run on alpine linux, but I was building for libc
when I should have been building for musl
.
The failing package was built using:
dotnet publish --self-contained true --runtime linux-x64 --framework netcoreapp2.1 --output /app
Changing the RID:
dotnet publish --self-contained true --runtime linux-musl-x64 --framework netcoreapp2.1 --output /app
produced a functional package. Notice the RID changed from linux-x64
to linux-musl-x64
. If I had read the .NET Core RID Catalog page this could have been avoided.
For me it was a stupid mistake: I started a wrong file.
For me with ASP.NET Core 2.0 on Azure, it was the appname.deps.json that did the trick. You need to copy it from your build directory to Azure.