Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hostfxr.dll load failure with arm64 app on arm64 Windows 11 host #65263

Closed
riverar opened this issue Feb 12, 2022 · 21 comments
Closed

Hostfxr.dll load failure with arm64 app on arm64 Windows 11 host #65263

riverar opened this issue Feb 12, 2022 · 21 comments

Comments

@riverar
Copy link
Contributor

riverar commented Feb 12, 2022

Description

After deploying a hello-world framework-dependent portable net6.0 app onto a Windows 11 arm64 host, attempts to launch that app result in failure.

image

Reproduction Steps

  1. Download/extract supplied dotnet_6_arm64_repro.zip (see below)
  2. dotnet publish
  3. Copy \bin\ARM64\Debug\net6.0\publish\ to arm64 machine
  4. Execute dotnet_6_arm64_repro.exe
  5. (Optional) Address the missing .NET 6.0.2 dependency by installing .NET 6.0 Desktop Runtime (v6.0.2) - Windows arm64, and revisit step 4.

Expected behavior

App to run and print Hello, World! successfully.

Actual behavior

App fails with:

Failed to load the dll from [C:\Program Files\dotnet\host\fxr\6.0.2\hostfxr.dll], HRESULT: 0x800700C1
The library hostfxr.dll was found, but loading it from C:\Program Files\dotnet\host\fxr\6.0.2\hostfxr.dll failed
  - Installing .NET prerequisites might help resolve this problem.
     https://go.microsoft.com/fwlink/?linkid=798306

Regression?

No response

Known Workarounds

No response

Configuration

Windows 11 22504.1010 (arm64)
Visual Studio 2022 17.0.5

Other information

dotnet_6_arm64_repro.zip

Host (useful for support):
  Version: 6.0.2
  Commit:  839cdfb0ec

.NET SDKs installed:
  No SDKs were found.

.NET runtimes installed:
  Microsoft.NETCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Core host trace, verbosity=4

Tracing enabled @ Sat Feb 12 21:16:51 2022 GMT
--- Invoked apphost [version: 6.0.2, commit hash: 839cdfb0ecca5e0be3dbccd926e7651ef50fdf10] main = {
C:\Users\Rafael\desktop\publish\dotnet_6_arm64_repro.exe
}
Redirecting errors to custom writer.
The managed DLL bound to this executable is: 'dotnet_6_arm64_repro.dll'
Can't open the SDK installed location registry key, result: 0x2
Using global installation location [C:\Program Files\dotnet] as runtime location.
Reading fx resolver directory=[C:\Program Files\dotnet\host\fxr]
Considering fxr version=[6.0.2]...
Detected latest fxr version=[C:\Program Files\dotnet\host\fxr\6.0.2]...
Resolved fxr [C:\Program Files\dotnet\host\fxr\6.0.2\hostfxr.dll]...
Failed to load the dll from [C:\Program Files\dotnet\host\fxr\6.0.2\hostfxr.dll], HRESULT: 0x800700C1
The library hostfxr.dll was found, but loading it from C:\Program Files\dotnet\host\fxr\6.0.2\hostfxr.dll failed
  - Installing .NET prerequisites might help resolve this problem.
     https://go.microsoft.com/fwlink/?linkid=798306
> dotnet --list-runtimes
Microsoft.NETCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

> dotnet --list-sdks
[no output]
@dotnet-issue-labeler dotnet-issue-labeler bot added area-Host untriaged New issue has not been triaged by the area owner labels Feb 12, 2022
@ghost
Copy link

ghost commented Feb 12, 2022

Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

After deploying a hello-world framework-dependent portable net6.0 app onto a Windows 11 arm64 host, attempts to launch that app result in failure.

image

Reproduction Steps

  1. Download/extract supplied dotnet_6_arm64_repro.zip (see below)
  2. dotnet publish
  3. Copy \bin\ARM64\Debug\net6.0\publish\ to arm64 machine
  4. Execute dotnet_6_arm64_repro.exe
  5. (Optional) Address the missing .NET 6.0.2 dependency by installing .NET 6.0 Desktop Runtime (v6.0.2) - Windows arm64, and revisit step 4.

Expected behavior

App to run and print Hello, World! successfully.

Actual behavior

App fails with:

Failed to load the dll from [C:\Program Files\dotnet\host\fxr\6.0.2\hostfxr.dll], HRESULT: 0x800700C1
The library hostfxr.dll was found, but loading it from C:\Program Files\dotnet\host\fxr\6.0.2\hostfxr.dll failed
  - Installing .NET prerequisites might help resolve this problem.
     https://go.microsoft.com/fwlink/?linkid=798306

Regression?

No response

Known Workarounds

No response

Configuration

Windows 11 22504.1010 (arm64)
Visual Studio 2022 17.0.5

Other information

dotnet_6_arm64_repro.zip

Author: riverar
Assignees: -
Labels:

area-Host, untriaged

Milestone: -

@vitek-karas
Copy link
Member

I didn't try on actual Windows ARM64, but following the repro steps I think the problem is with the publish. The command line dotnet publish will not by default pick up the Properties\FolderProfile.pubxml, so it publishes as portable app (no target architecture). But it will still produce an apphost, the exe. Since no target architecture is specified, it will produce the apphost for the RID of the SDK it's using - which is presumably something like win-x64.

So if I follow the repro steps, the produced .exe is a win-x64 executable. When executed on win-arm64, this will start an emulated x64 process, which will then find the arm64 hostfxr and that fails to load. The error code is ERROR_BAD_EXE_FORMAT - which means "wrong architecture" in most cases.

I think the main problem here is that apphost is not clever enough to default to the x64 install location on arm64 hardware. It did look into registry, into the x64 key, but that doesn't exist - failed with 0x2 ERROR_FILE_NOT_FOUND. So if defaults to the hardcoded install location - which should be C:\Program Files\dotnet\x64 on win-arm64, but it doesn't. (if it did, it would have failed saying that it's missing the runtime and would point out that it needs x64 runtime).

We sort of fixed this with this PR: #59890
What that will do is make the x64 apphost look for the runtime in the right x64 location - and fail to find any runtime and correctly ask for installing the x64 runtime.

Maybe we should consider backporting this fix to 6.0.

Other improvements:

@riverar
Copy link
Contributor Author

riverar commented Feb 13, 2022

Hm @vitek-karas, I can verify the apphost is x64. But no configuration of publish commands appears to correct this. (For example, I tried dotnet publish /p:PublishProfile=.\Properties\PublishProfiles\FolderProfile.pubxml /p:Platform=ARM64).

@vitek-karas
Copy link
Member

I think that Platform is not the right variable for this (but I admit knowing very little about which one is the right one). What should definitely work is: dotnet publish -r win-arm64 or dotnet publish -a arm64.

@pfeifix
Copy link

pfeifix commented Apr 25, 2022

Any updates on this issue?

I get the same error message when creating an inital migration for a database via the EntityFramework CLI tools, for example when trying to execute:

dotnet ef migrations add InitialCreate

strictly following the process described by Microsoft: https://docs.microsoft.com/en-us/ef/core/managing-schemas/migrations/?tabs=dotnet-core-cli

The exact error is

Failed to load the dll from [C:\Program Files\dotnet\host\fxr\6.0.4\hostfxr.dll], HRESULT: 0x800700C1
The library hostfxr.dll was found, but loading it from C:\Program Files\dotnet\host\fxr\6.0.4\hostfxr.dll failed
  - Installing .NET prerequisites might help resolve this problem.
     https://go.microsoft.com/fwlink/?linkid=798306

The error might be related to the EF Core .NET CLI tools (https://docs.microsoft.com/en-us/ef/core/cli/dotnet) when running on ARM64. Maybe anyone from Microsoft has to look into this?

@riverar
Copy link
Contributor Author

riverar commented Apr 25, 2022

@vitek-karas Friendly ping. Would be great if we could get this into 6.0 servicing, given it's a LTS release.

@vitek-karas
Copy link
Member

We're looking into it, but note that it might not fix the dotnet-ef problem fully. There's a longer discussion about that specific tool here: dotnet/efcore#27787

@pfeifix
Copy link

pfeifix commented Apr 26, 2022

I would greatly appreciate if someone can present me a workaround for using the basic database migrations commands with dotnet-ef (see my post above) in VS Code. At the moment I am stuck with my work on my Surface Pro X running Windows on ARM64. :-(

@pfeifix
Copy link

pfeifix commented Apr 26, 2022

Update: Problem is resolved, see dotnet/efcore#27787 (comment) .

@elinor-fung
Copy link
Member

Would be great if we could get this into 6.0 servicing, given it's a LTS release.

We have backported a fix into 6.0 servicing which should make the x64 apphost look for the runtime in the correct location for the x64 runtime (and fail reasonably if one doesn't exist). It will be in 6.0.6.

@riverar
Copy link
Contributor Author

riverar commented May 4, 2022

@elinor-fung That's fantastic, thanks for closing the loop!

@AlisaZhang3
Copy link

AlisaZhang3 commented Jun 16, 2022

We encounter the similar issue in the latest main branch. When we create a new console core 6.0 project and change the target to X64. Start debugging. VS will pop up an error and the error is NET 7 not NET 6.
image
image

@vitek-karas
Copy link
Member

Can you please check the version of the apphost?
I guess the easiest way would be to set COREHOST_TRACE=1 and run the app in question. It will print out much more detailed trace including the version of the host.

@AlisaZhang3
Copy link

Ok. I have collected the detailed trace as below:
image

@vitek-karas
Copy link
Member

Do you have x64 runtime installed?
Basically is there a file D:\Program Files\dotnet\x64\dotnet.exe ?

@AlisaZhang3
Copy link

I checked the folder and found no x64 runtime installed
image

@vitek-karas
Copy link
Member

Well - it's weird that there are directories there but no dotnet.exe. It's as if the install is either corrupted or something else went wrong.

In any case, I don't think your apphost has the fix mentioned above - the commit hash it has is from Apr 13, while the fix was ported to 6.0 in May. @elinor-fung do you know which version of 6 has the fix and if it's in one of the public releases?

@elinor-fung
Copy link
Member

6.0.5 does not have the fix. The fix is in 6.0.6 - just released recently (14-JUN), so you'd need to rebuild the app with that to pick up the fixed apphost.

@roofiq
Copy link

roofiq commented Jun 27, 2022

Hello, seems like 6.0.6 didn't fix the issue. I'm still experiencing this error, running on Windows Server 2022 version 21H2 x64.

@vitek-karas
Copy link
Member

@roofiq This GitHub issue is specific to the behavior on ARM64. Since you're running into a similar error message but on X64 I suggest you create a new issue as it's very likely not related.
Please try to collect host traces as per https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#corehost_trace.

@agocke
Copy link
Member

agocke commented Jul 1, 2022

Closing as resolved

@agocke agocke closed this as completed Jul 1, 2022
@agocke agocke moved this to Done in AppModel Jul 1, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jul 1, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

7 participants