The library 'hostpolicy.dll' required to execute the application

Viewed 15629

After adding log4net, I end up with the following error message in publication via the dotnet command (IIS giving a 500 error).

A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'MonPath'

Framework : .Net CoreApp 1.1

In Debug mode via VS2017, the application is running.

In my .csproj :

PackageReference Include="Microsoft.NETCore.DotNetHostPolicy" Version="1.1.2" PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" TargetFramework netcoreapp1.1

I have found this solution for project.json but how to apply it to .csproj?

"compilationOptions": { "emitEntryPoint": true }

6 Answers

I got this error trying to run the .exe from the path:

[myProjectPath]\obj\Debug\netcoreapp3.1

Instead of the path:

[myProjectPath]\bin\Debug\netcoreapp3.1

Just in case somebody else is making the same, dopey mistake.

for my .net Core 3.1 app in the 'Release' folder there were some files missing, like

  • '<proj_name>.deps.json'
  • '<proj_name>.runtimeconfig.json'

and some other. Well, it happened because I added one console project as a dependency to another console project. And for the dependent project, the files were missing. This caused the exception. The files are required for 'framework-dependent' applications otherwise it will be run as 'self-contained' and will search for 'hostpolicy.dll' in 'C:\Program Files\dotnet' folder, that is not there because of whatever reason. enter image description here

This is an old question that seems to have multiple possible answers, particularly if experienced during an Azure deployment. In my case, I ran into this when trying to run an ASP.NET Core 2.1 app deployed to IIS on-premise.

For me this was caused by trying to run a self-contained app - an app that output to EXE instead of a DLL, and was not runtime-dependent - using a dotnet command. I didn't need to use the dotnet CLI to execute what was already an EXE; I just had to execute it directly. However this error message was completely misleading in that case.

I ran into this problem when trying to execute the application directly on the server to troubleshoot why it appeared not to start in IIS, which on an unrelated note, was caused by not having the proper version of the ASP.NET Core Hosting Bundle installed.

Related