The library hostpolicy.dll was not found
Solution 1
This error message is unhelpful. The actual problem is a missing emitEntryPoint
property:
"buildOptions": {
...
"emitEntryPoint": true
},
Once this is added, the compiler will let you know about any other problems (like a missing static void Main()
method). Successfully compiling the project will result in an output that dotnet run
can execute.
Solution 2
Update for dotnet core 2.0 and beyond: the file appname.runtimeconfig.json (for both debug and release configuration) is needed in the same path as appname.dll.
It contains:
{
"runtimeOptions": {
"tfm": "netcoreapp2.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "2.0.0"
}
}
}
then dotnet.exe exec "path/to/appname.dll" [appargs]
works.
Solution 3
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.
Edit: Should be fixed in .NET SDK 5.0.200.
Solution 4
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.
Solution 5
This occurred when a Visual Studio 2019 preview upgrade .Net Core to the latest preview (specifically .Net Core 3.1.100-preview2-014569).
Reinstalling/repairing .Net Core 3.0.100 solved the problem for me.
Nate Barbettini
Developer, author, and speaker. I'm passionate about helping people learn how to write clean, secure code. I wrote The Little ASP.NET Core Book, a free book that teaches you how to build web apps with ASP.NET Core. I also have deep-dive video courses published on LinkedIn Learning: Building and Securing RESTful APIs in ASP.NET Core Deploying ASP.NET Core Applications Learning SignalR with ASP.NET Core
Updated on December 08, 2021Comments
-
Nate Barbettini over 2 years
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 dodotnet run
:λ dotnet run Project RazorPrecompiler (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation. A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in [path].
My project.json looks like this:
{ "buildOptions": { "warningsAsErrors": true }, "dependencies": { "Microsoft.AspNetCore.Razor": "1.0.0", "Microsoft.NETCore.App": { "type": "platform", "version": "1.0.0" } }, "description": "Precompiles Razor views.", "frameworks": { "netcoreapp1.0": { "imports": [ ] } }, "version": "1.2.0" }
What is
hostpolicy.dll
, and why is it missing?