Build successful? SHIP IT!

EF Core fails to load hostpolicy.dll when RuntimeIdentifier is win-x86

This post was most recently updated on November 2nd, 2019.

Reading Time: 2 minutes.

Ran into another interesting one when working with a .NET Core 3.0 project and Entity Framework Core – this time, RuntimeIdentifier configuration causing trouble. In short, running Update-Database (to apply code-first migrations to your local database) locally would return this, annoying error:

Failed to load the dll from [runtimepath]\win-x86\hostpolicy.dll], HRESULT: 0x800700C1
An error occurred while loading required library hostpolicy.dll from [runtimepath]\win-x86\]

I suspect this can happen with any x86 runtimeIdentifier, but the one I had specified in my .csproj-file was this:

<RuntimeIdentifier>win-x86</RuntimeIdentifier>

This value (or similar) is required for a self-contained ASP.NET Core deployment. And I’m sure there’s a few other reasons why you might need it in the file.

RuntimeIdentifier in a .csproj file. With a few other hacks, unfortunately.
RuntimeIdentifier in a .csproj file. With a few other hacks, unfortunately. :)

Description

Table of Contents

My investigation led me to this issue on GitHub, which proposes a solution – but alas, the solution they had (changing the RuntimeIdentifier as follows) didn’t work for me.

<RuntimeIdentifiers>win10-x64;win7-x86</RuntimeIdentifiers>

While it sounds like it worked for some users, it really didn’t for me. Instead I got a new error:

The "HasTrailingSlash" function only accepts a scalar value, but its argument "$(PublishDir)" evaluates to "bin\Debug\netcoreapp3.0\win10-x64;win7-32x\publish\" which is not a scalar value. C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets

This, as seen below in a screenshot, was especially funny because I was definitely not using Visual Studio 2017 – but instead, Visual Studio 2019, which is required to get Blazor development going at all!

The "HasTrailingSlash" function only accepts a scalar value, but its argument "$(PublishDir)" evaluates to "bin\Debug\netcoreapp3.0\win10-x64;win7-32x\publish\" which is not a scalar value. C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets
The “HasTrailingSlash” function only accepts a scalar value, but its argument “$(PublishDir)” evaluates to “bin\Debug\netcoreapp3.0\win10-x64;win7-32x\publish\” which is not a scalar value. C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets

The error above blocked me from building anything in Visual Studio.

Also, since I’m packaging the solution as a self-contained application, I would probably run into this as well: https://github.com/dotnet/cli/issues/10474

So overall, I had to find a runtime identifier that would let me use the Entity Framework Core code-first migrations.

Solution

Eh, well – long story short, it’s this easy. Change the RuntimeIdentifier to this (or similar, I’d suppose):

<RuntimeIdentifier>win10-x64</RuntimeIdentifier>

While this could easily have side effects, you actually don’t need to check this change in at all. Just revert it before committing your changes – or even just after adding the new migration :)

Antti K. Koskela

Antti Koskela is a proud digital native nomadic millennial full stack developer (is that enough funny buzzwords? That's definitely enough funny buzzwords!), who works as a Solutions Architect for Valo Intranet, the product that will make you fall in love with your intranet. Working with the global partner network, he's responsible for the success of Valo deployments happening all around the world.

He's been a developer from 2004 (starting with PHP and Java), and he's been bending and twisting SharePoint into different shapes since MOSS. Nowadays he's not only working on SharePoint, but also on .NET projects, Azure, Office 365 and a lot of other stuff.

This is his personal professional (e.g. professional, but definitely personal) blog.
mm

Leave a Reply

avatar
5000
  Subscribe  
Notify of