This article describes how to fix error “There was an error running the selected code generator: ‘Failed to load the dll from \bin\Debug\netcoreapp\win-x86\hostpolicy.dll, HRESULT: 0x800700C1 An error occurred while loading required library hostpolicy.dll'” when you’re adding a new scaffolded item (such as a Razor page or ASP.NET Core MVC Controller).
Description
Imagine this: You’re developing your run-of-the-mill, basic, everyday ASP.NET Core web application. You need to add a new scaffolded item – that is,

This’ll result in an error somewhat like below:
There was an error running the selected code generator: 'Failed to load the dll from [projectpath]\bin\Debug\netcoreapp\win-x86\hostpolicy.dll, HRESULT: 0x800700C1 An error occurred while loading required library hostpolicy.dll from ...
Solution
We have, in fact, seen this one before! A different context, similar error – so we actually know how to fix it!
For the other post (about a similar error with EF Core), see the post below. Even though it describes a fix to an issue that arises when running Update-Database, the underlying error is in fact the same that causes the error “There was an error running the selected code generator: (HRESULT: 0x800700C1)” for us here.
- How to fix “System.IO.FileSystem: Could not find a part of the path \AppData\Local\AzureFunctionsTools\Releases\3.17.0\workers. Value cannot be null. (Parameter ‘provider’)” when running Azure Functions locally? - January 12, 2021
- How to nuke the Identity Cache in Visual Studio? - January 11, 2021
- Fixing unexpected Microsoft.AspNetCore package errors after a dependency update - January 6, 2021