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

[BUG] pre-release crashes on start, can't load hostfxr.dll #5877

Closed
josh-hemphill opened this issue Jun 28, 2023 · 12 comments
Closed

[BUG] pre-release crashes on start, can't load hostfxr.dll #5877

josh-hemphill opened this issue Jun 28, 2023 · 12 comments

Comments

@josh-hemphill
Copy link

Steps to reproduce

  1. Update pre-release version of C# extension and devkit
  2. Wait for it to try to load then crash
  3. View extension output
  4. See error

Actual behavior

Before manually setting dotnet path:

Failed to load the dll from [c:\Users\myusername\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\7.0.8\host\fxr\7.0.8\hostfxr.dll], HRESULT: 0x800700C1
The library hostfxr.dll was found, but loading it from c:\Users\myusername\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\7.0.8\host\fxr\7.0.8\hostfxr.dll failed

after

Failed to load the dll from [C:\Program Files\dotnet\host\fxr\7.0.7\hostfxr.dll], HRESULT: 0x800700C1
The library hostfxr.dll was found, but loading it from C:\Program Files\dotnet\host\fxr\7.0.7\hostfxr.dll failed

Environment data

VS Code version: 1.79.2
C# Extension version: 2.0.248

Dotnet Information

.NET SDK:
Version: 7.0.304
Commit: 7e794e2806

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.304\

Host:
Version: 7.0.7
Architecture: x64
Commit: 5b20af47d9

.NET SDKs installed:
3.1.426 [C:\Program Files\dotnet\sdk]
5.0.416 [C:\Program Files\dotnet\sdk]
7.0.304 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment Variables:
Not set

global.json file:
Not found

Visual Studio Code Extensions
Extension Author Version
azure-account ms-vscode 0.11.5
better-comments aaron-bond 3.0.2
code-spell-checker streetsidesoftware 2.20.5
csdevkit ms-dotnettools 0.1.103
csharp ms-dotnettools 1.26.0
data-workspace-vscode ms-mssql 0.5.0
EditorConfig EditorConfig 0.16.4
git-graph mhutchie 1.30.0
gitlens eamodio 14.0.1
goto-alias antfu 0.1.1
html-css-class-completion Zignd 1.20.0
i18n-ally lokalise 2.9.1
live-server ms-vscode 0.4.8
markdown-all-in-one yzhang 3.5.1
material-icon-theme PKief 4.28.0
msbuild-project-tools tintoy 0.4.9
mssql ms-mssql 1.19.1
npm-intellisense christian-kohler 1.4.4
path-intellisense christian-kohler 2.8.4
remote-containers ms-vscode-remote 0.295.0
remote-explorer ms-vscode 0.4.0
remote-server ms-vscode 1.2.1
remote-ssh ms-vscode-remote 0.102.0
remote-ssh-edit ms-vscode-remote 0.86.0
remote-wsl ms-vscode-remote 0.79.5
sonarlint-vscode SonarSource 3.19.0
sql-bindings-vscode ms-mssql 0.4.0
sql-database-projects-vscode ms-mssql 1.1.1
synthwave-vscode RobbOwen 0.1.15
volar Vue 1.8.3
vscode-conventional-commits vivaxy 1.25.0
vscode-dotnet-runtime ms-dotnettools 1.6.0
vscode-drawio hediet 1.6.6
vscode-eslint dbaeumer 2.4.2
vscode-html-css ecmel 1.13.1
vscode-markdownlint DavidAnson 0.51.0
vscode-remote-extensionpack ms-vscode-remote 0.24.0
vscode-taskexplorer spmeesseman 2.13.2
vscode-thunder-client rangav 2.8.3
vscode-xml redhat 0.25.0
vscode-yaml redhat 1.13.0
vscodeintellicode-csharp ms-dotnettools 0.1.23
@josh-hemphill josh-hemphill changed the title [BUG] C# pre-release can't load hostfxr.dll, crashes extension [BUG] C# pre-release crashes on start, can't load hostfxr.dll Jun 28, 2023
@josh-hemphill josh-hemphill changed the title [BUG] C# pre-release crashes on start, can't load hostfxr.dll [BUG] pre-release crashes on start, can't load hostfxr.dll Jun 28, 2023
@dibarbet
Copy link
Member

dibarbet commented Jun 29, 2023

@josh-hemphill could you post a screenshot of your extensions folder (particularly interested in the name of the ms-dotnettools.csharp-<version>-<platform> folder).
image

We've had issues before where the incorrect platform gets downloaded from the marketplace causing the runtime to fail to start the server.

If you do see the wrong platform, uninstall the extension, close vscode, delete the folder in the extensions folder, and reinstall.

@josh-hemphill
Copy link
Author

The environment I'm running this stuff in is pretty restrictive, I don't think I'll be able to share any images.
They're all win32-x64, which seems correct. I've uninstalled and reinstalled several time, and still run into the same error.

@gregg-miskelly
Copy link
Contributor

Ignore this if it is obvious to everyone, but just in case: 0x800700C1 is HRESULT_FROM_WIN32(ERROR_BAD_EXE_FORMAT) which almost always means that one is trying to load a dll that targets the wrong processor architecture into a process (example: loading an x64 dll into an x86 process).

@josh-hemphill
Copy link
Author

I looked through my extensions.json in the extensions directory, and it looks like I'm also using RedHat's XML extension which is platform dependent, and lists win32-x64 and runs fine.
And when I run the release version of vscode-csharp it's still win32-x64 and running fine. 🤔

Is there anything special about the hostfxr.dll?

@dibarbet
Copy link
Member

Ignore this if it is obvious to everyone, but just in case: 0x800700C1 is HRESULT_FROM_WIN32(ERROR_BAD_EXE_FORMAT) which almost always means that one is trying to load a dll that targets the wrong processor architecture into a process (example: loading an x64 dll into an x86 process).

Thanks - I actually didn't know that, so that's good to know.

They're all win32-x64, which seems correct. I've uninstalled and reinstalled several time, and still run into the same error.

I looked through my extensions.json in the extensions directory, and it looks like I'm also using RedHat's XML extension which is platform dependent, and lists win32-x64 and runs fine.
And when I run the release version of vscode-csharp it's still win32-x64 and running fine.

Very strange... it definitely seems like there is a platform mismatch somewhere.
A couple potential things to try

  1. Set the dotnet.server.trace setting to Trace and reload the window. Then check the C# output window, right at the beginning it should print something like Starting server at c:\Users\dabarbet\.vscode\extensions\ms-dotnettools.csharp-2.0.248-win32-x64\.roslyn\Microsoft.CodeAnalysis.LanguageServer.exe. Could you send me what that is?
  2. Could you share the actual hostfxr.dll (from the path indicated in the error) and the Microsoft.CodeAnalysis.LanguageServer.dll (from the ms-dotnettools.csharp.../.roslyn extension directory).
    a. If you can't due to the environment restrictions, would you be able to open the language server dll in something like ILspy and confirm that it is x64?
  3. Maybe the downloaded runtime is incorrect, we can try deleting it to get it to re-download. With vscode closed, Delete the .dotnet folder from c:\Users\myusername\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\. That should tell the runtime extension to re-download the runtime. However since you already tried pointing it to a different runtime, I doubt this will work.

Is there anything special about the hostfxr.dll?

It's part of the runtime. I don't know too much about it other than that, other than we've seen similar errors when the marketplace downloads the extension for the wrong platform (e.g. microsoft/vscode-dotnettools#141)

@josh-hemphill
Copy link
Author

The Microsoft.CodeAnalysis.LanguageServer.dll has a Microsoft.CodeAnalysis.LanguageServer.deps.json which lists it as win-x64 (To be precise: runtimeTarget.name: ".NETCoreApp,Version=v7.0/win-x64")

Well...
I tried turning on server trace... And it doesn't seem to be broken anymore. 🤷
I think the VM I'm working in restarted overnight, maybe that fixed it?

I guess I'll close and just reopen if the issue returns. (Which I'm sure it will the second I try to get someone else set up with the extension.😆😢)

@dibarbet
Copy link
Member

Yup that dll all looks correct. I'm glad to hear it's working now, but definitely confused on why it didn't work before. Do tag me and re-open the issue if it comes back though.

@333fred 333fred reopened this Jun 30, 2023
@333fred
Copy link
Member

333fred commented Jun 30, 2023

I'm seeing this myself as well:

Dotnet path: C:\Program Files\dotnet\dotnet.exe
Activating C# + C# Dev Kit + C# IntelliCode...
Starting server at c:\git\vscode-csharp\.roslyn\Microsoft.CodeAnalysis.LanguageServer.exe
Failed to load the dll from [C:\Program Files\dotnet\host\fxr\8.0.0-preview.5.23280.8\hostfxr.dll], HRESULT: 0x800700C1
The library hostfxr.dll was found, but loading it from C:\Program Files\dotnet\host\fxr\8.0.0-preview.5.23280.8\hostfxr.dll failed
  - Installing .NET prerequisites might help resolve this problem.
     https://go.microsoft.com/fwlink/?linkid=798306
[Error - 11:10:55 PM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 
[Info  - 11:10:55 PM] Connection to server got closed. Server will restart.

@333fred
Copy link
Member

333fred commented Jun 30, 2023

image
For myself, I do see that the language server appears to be x86, not x64.

@333fred
Copy link
Member

333fred commented Jun 30, 2023

@josh-hemphill, by any chance did you run a gulp vsix:release:package while you were developing? I suspect that was the source of my issue: I ran that, realized it was going to create all the packages, and then cancelled out. But it seems like it replaced my .roslyn copy with an x86 version. Deleting and rerunning gulp installDependencies seems to have fixed it, but we should document this pitfall somewhere.

@josh-hemphill
Copy link
Author

Nope, didn't run anything like that, but I think I had been messing with some configs and got stuck in an extension update loop for a while for some reason. But it all just kinda resolved itself after a reboot.

@dibarbet
Copy link
Member

Closing this issue - it's quite stale and we've fixed a number of similar issues. If there are still problems on the latest versions, please open a new issue with updated logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants