#SharePointProblems | Koskila.net

Solutions are worthless unless shared! Antti K. Koskela's Personal Professional Blog

Adding new MVC/Razor items fails throwing an error about hostpolicy.dll

koskila
Reading Time 2 min
Word Count 237 words
Comments 0 comments
Rating n/a (0 votes)
View

This article describes how to fix the 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) in Visual Studio.

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, something like a Razor page or an MVC controller.

How to create a new scaffolded item in ASP.NET Core

How to create a new scaffolded item for ASP.NET Core in Visual Studio

This will result in an error somewhat like the 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.

Essentially - modify your project file to have a RuntimeIdentifiers -node instead of RuntimeIdentifier. See below for more details:

https://www.koskila.net/ef-core-fails-to-load-hostpolicy-dll-when-runtimeidentifier-is-win-x86/

Comments

Interactive comments not implemented yet. Showing legacy comments migrated from WordPress.
Whitewater Magpie Ltd.
© 2025
Static Site Generation timestamp: 2025-08-21T07:25:06Z