dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 671 forks source link

LanguageServer Fails to start on Mac M1 #5873

Closed jimAtLoyal closed 11 months ago

jimAtLoyal commented 1 year ago

Type: Bug

The language server fails to start whenever I open VSCode. Following tips on other posts I uninstalled extensions, and also deleted from my extension folder and keep getting the same results. I suspect it has to do with the M1 architecture since I have to point my dotnet to the x64 version for general use.

From the C# Log

Dotnet path: /Users/jwallace/Library/Application Support/Code - Insiders/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.8/dotnet
Activating C# + C# Dev Kit + C# IntelliCode...
Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.LanguageServer, Version=4.7.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
[Error - 6:14:58 AM] Server initialization failed.
  Message: Pending response rejected since connection got disposed
  Code: -32097 

Here's my extension folder

> dir /Users/me/.vscode-insiders/extensions

    Directory: /Users/me/.vscode-insiders/extensions

UnixMode   User             Group                 LastWriteTime           Size Name
--------   ----             -----                 -------------           ---- ----
drwxr-xr-x me         staff                6/1/2023 06:48            320 adisreyaj.swagger-snippets-0.0.1
drwxr-xr-x me         staff                6/1/2023 06:48            352 arjun.swagger-viewer-3.1.2
drwxr-xr-x me         staff               6/22/2023 11:04            384 bierner.markdown-mermaid-1.19.0
drwxr-xr-x me         staff               6/14/2023 07:42            480 davidanson.vscode-markdownlint-0.51.0
drwxr-xr-x me         staff               6/22/2023 11:04            480 dbaeumer.vscode-eslint-2.4.2
drwxr-xr-x me         staff                6/1/2023 06:48            448 dotjoshjohnson.xml-2.5.1
drwxr-xr-x me         staff                6/1/2023 06:48            416 editorconfig.editorconfig-0.16.4
drwxr-xr-x me         staff               6/13/2023 07:21            416 github.codespaces-1.14.8
drwxr-xr-x me         staff                6/8/2023 06:46            288 github.copilot-chat-0.3.2023060801
drwxr-xr-x me         staff                6/1/2023 06:48            224 github.copilot-labs-0.14.884
drwxr-xr-x me         staff               6/27/2023 12:18            288 github.copilot-nightly-1.93.191
drwxr-xr-x me         staff               6/28/2023 06:12            288 github.copilot-nightly-1.93.194
drwxr-xr-x me         staff               6/13/2023 07:21            864 github.vscode-pull-request-github-0.66.1
drwxr-xr-x me         staff                6/1/2023 06:48            384 ipedrazas.kubernetes-snippets-0.1.9
drwxr-xr-x me         staff                6/1/2023 06:48            832 jebbs.plantuml-2.17.5
drwxr-xr-x me         staff                6/1/2023 06:48            320 johnpapa.vscode-peacock-4.2.2
drwxr-xr-x me         staff                6/1/2023 06:48            320 mindaro-dev.file-downloader-1.0.12
drwxr-xr-x me         staff                6/1/2023 06:49            640 mindaro.mindaro-2.0.120230525
drwxr-xr-x me         staff                6/1/2023 06:49            544 ms-azure-devops.azure-pipelines-1.208.0
drwxr-xr-x me         staff                6/1/2023 06:49            544 ms-azuretools.vscode-azureresourcegroups-0.7.5
drwxr-xr-x me         staff                6/1/2023 06:49            512 ms-azuretools.vscode-cosmosdb-0.19.4
drwxr-xr-x me         staff                6/1/2023 06:49            416 ms-azuretools.vscode-docker-1.25.1
drwxr-xr-x me         staff               6/23/2023 11:19           1056 ms-dotnettools.csdevkit-0.2.70-darwin-arm64
drwxr-xr-x me         staff               6/23/2023 11:19            544 ms-dotnettools.csharp-2.0.238-darwin-arm64
drwxr-xr-x me         staff               6/14/2023 07:42           1024 ms-dotnettools.dotnet-interactive-vscode-1.0.4313020
drwxr-xr-x me         staff                6/1/2023 06:49            672 ms-dotnettools.vscode-dotnet-pack-1.0.12
drwxr-xr-x me         staff               6/12/2023 06:59            288 ms-dotnettools.vscode-dotnet-runtime-1.6.0
drwxr-xr-x me         staff               6/23/2023 11:19            448 ms-dotnettools.vscodeintellicode-csharp-0.1.9-darwin-arm64
drwxr-xr-x me         staff                6/9/2023 06:32            864 ms-kubernetes-tools.vscode-kubernetes-tools-1.3.13
drwxr-xr-x me         staff                6/1/2023 06:49            320 ms-mssql.data-workspace-vscode-0.5.0
drwxr-xr-x me         staff                6/6/2023 08:38            960 ms-mssql.mssql-1.19.1
drwxr-xr-x me         staff                6/1/2023 06:49            352 ms-mssql.sql-bindings-vscode-0.4.0
drwxr-xr-x me         staff                6/1/2023 06:49            416 ms-mssql.sql-database-projects-vscode-1.1.1
drwxr-xr-x me         staff                6/1/2023 06:49           1056 ms-python.isort-2022.8.0
drwxr-xr-x me         staff               6/14/2023 07:42           1280 ms-python.python-2023.10.1
drwxr-xr-x me         staff               6/22/2023 11:05            384 ms-python.vscode-pylance-2023.6.30
drwxr-xr-x me         staff               6/22/2023 11:04           1088 ms-toolsai.jupyter-2023.5.1101742258-darwin-arm64
drwxr-xr-x me         staff                6/5/2023 14:13            352 ms-toolsai.jupyter-keymap-1.1.2
drwxr-xr-x me         staff                6/1/2023 06:49            416 ms-toolsai.jupyter-renderers-1.0.15
drwxr-xr-x me         staff                6/1/2023 06:49            576 ms-toolsai.vscode-jupyter-cell-tags-0.1.8
drwxr-xr-x me         staff                6/1/2023 06:49            544 ms-toolsai.vscode-jupyter-slideshow-0.1.5
drwxr-xr-x me         staff               6/27/2023 12:18            928 ms-vscode-remote.remote-containers-0.297.0
drwxr-xr-x me         staff                6/1/2023 06:49           1184 ms-vscode-remote.remote-ssh-0.102.0
drwxr-xr-x me         staff                6/1/2023 06:49            960 ms-vscode-remote.remote-ssh-edit-0.86.0
drwxr-xr-x me         staff               6/14/2023 13:25            928 ms-vscode-remote.remote-wsl-0.79.5
drwxr-xr-x me         staff                6/1/2023 06:49            320 ms-vscode-remote.vscode-remote-extensionpack-0.24.0
drwxr-xr-x me         staff                6/1/2023 06:49            608 ms-vscode.azure-account-0.11.5
drwxr-xr-x me         staff                6/1/2023 06:49            512 ms-vscode.hexeditor-1.9.11
drwxr-xr-x me         staff                6/1/2023 06:49            960 ms-vscode.live-server-0.4.8
drwxr-xr-x me         staff                6/7/2023 02:12            576 ms-vscode.powershell-2023.6.0
drwxr-xr-x me         staff                6/1/2023 06:49            864 ms-vscode.remote-explorer-0.4.0
drwxr-xr-x me         staff                6/8/2023 11:08            864 ms-vscode.remote-server-1.2.1
drwxr-xr-x me         staff                6/1/2023 06:48            544 redhat.vscode-yaml-1.13.0
drwxr-xr-x me         staff                6/5/2023 06:26            416 smcpeak.default-keys-windows-0.0.10
drwxr-xr-x me         staff               6/12/2023 06:25            384 streetsidesoftware.code-spell-checker-2.20.5
drwxr-xr-x me         staff                6/1/2023 06:54            608 yzhang.markdown-all-in-one-3.5.1
drwxr-xr-x me         staff               6/23/2023 11:11            512 zbecknell.t4-support-0.7.0
-rw-r--r-- me         staff               6/28/2023 06:12          32792 extensions.json

Extension version: 2.0.238 VS Code version: Code - Insiders 1.79.0-insider (Universal) (c3867859cf3e1a73f3ddce5ad36b3791b7883d88, 2023-06-01T05:26:38.346Z) OS version: Darwin arm64 22.5.0 Modes:

System Info |Item|Value| |---|---| |CPUs|Apple M1 Pro (8 x 24)| |GPU Status|2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled| |Load (avg)|4, 6, 6| |Memory (System)|16.00GB (0.06GB free)| |Process Argv|--crash-reporter-id ab336b3b-928a-4cbb-928e-f29f273c3b25| |Screen Reader|no| |VM|0%|
A/B Experiments ``` vsliv695:30137379 vsins829:30139715 vsliv368:30146709 vsreu685:30147344 python383cf:30185419 vspor879:30202332 vspor708:30202333 vspor363:30204092 vslsvsres303:30308271 pythontb:30258533 pythonptprofiler:30281269 vshan820:30294714 vscod805:30301674 bridge0708:30335490 bridge0723:30353136 vsaa593cf:30376535 pythonvs932:30404738 py29gd2263:30776702 vsclangdf:30492506 c4g48928:30535728 dsvsc012:30540252 pynewext54:30618038 pylantcb52:30590116 pyind779:30611226 pythonsymbol12:30651887 a9j8j154:30646983 showlangstatbar:30737417 pythonms35:30671666 03d35959:30757351 ecj1e332:30687743 pythonfmttext:30716741 pythoncmvfstr:30726892 fixshowwlkth:30771523 hideindicator:30766887 pythongtdpath:30726887 i26e3531:30769768 gsof1:30771514 e440d664:30776459 pythonnosmt12:30773574 pythonidxpt:30768918 pythondjangots:30768917 pythonnoceb:30776497 copilotsettingt:30767686 e537b577:30772214 synctok:30776453 dsvsc013:30777762 dsvsc014:30777825 ```
dibarbet commented 1 year ago

The extension does look like it is installed for the correct platform (darwin-arm64) and should work generally on M1 macs, so it doesn't necessarily look like an install issue.

Could you clarify what this means though?

I suspect it has to do with the M1 architecture since I have to point my dotnet to the x64 version for general use.

Since the extension is using an arm64 version, I don't think it will work with an x64 dotnet. However it should be downloading and running the arm64 version of the dotnet runtime (from here Dotnet path: /Users/jwallace/Library/Application Support/Code - Insiders/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.8/dotnet

jimAtLoyal commented 1 year ago

To clarify my comment, to use dotnet in general for building, debugging, etc. I have to install the x64 version and alias dotnet to /usr/local/share/dotnet/x64/dotnet not the arm64. It's been a long time since I set up this box and as I recall using x64 may be due to a third-party NuGet package.

I did notice I have /Users/.../.vscode-insiders/extensions/ms-dotnettools.csharp-2.0.248-darwin-arm64 and /Users/.../.vscode-insiders/extensions/ms-dotnettools.csharp-2.0.238-darwin-arm64 folder both with the LanguageServer assembly

jimAtLoyal commented 1 year ago

I was running from ~/Downloads, so I decided to start clean

  1. I uninstalled from ~/Downloads
  2. I downloaded latest VSCode insiders (1.80.0), put in Applications folder
  3. I installed only C# Dev Kit insiders
  4. Restart VSCode
  5. Open C# Project

Now in the C# log I only see this. Does this mean it's running?

Dotnet path: /Users/.../Library/Application Support/Code - Insiders/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.8/dotnet
Activating C# + C# Dev Kit + C# IntelliCode...
info: LanguageServerHost[0]
      Starting server...

When opening the Solution Explorer it says A compatible.NET SDK was not found and in the Projects Log it says

2023-06-30 06:43:31.661 [info] Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.VisualStudio.ProjectSystem.Server.BuildHost, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
[createdump] thread_get_state(55f09) FAILED (os/kern) invalid argument (4)
[createdump] Failure took 9ms

2023-06-30 06:43:33.625 [info] Project system initialization finished. 0 project(s) are loaded, and 5 failed to load.
JoeRobich commented 1 year ago

@jimAtLoyal Currently you will need to have matching architecture for the SDK and extensions as the extensions need to load components out of the installed SDK. If it is necessary to stay on x64, you could install an x64 build of VS Code. Otherwise, you will need to install an arm64 build of the .NET SDK.

jimAtLoyal commented 1 year ago

I have both x64 and arm64 of .NET SDK 7 installed.

dibarbet commented 1 year ago

Now in the C# log I only see this. Does this mean it's running?

Yup looks like the C# lsp server is running fine now. But based on the other logs you got from devkit, devkit is failing to load the project.

When opening the Solution Explorer it says A compatible.NET SDK was not found and in the Projects Log it says

Is the project you're trying to load also targeting .net 7? Or do you have a global.json pointing it at a different SDK? Devkit could also be getting confused by the presence of both the x64 and arm64 version of the sdk, but I'm not familiar enough with their side to know if that could trip them up. Tagging @lifengl and @tmeschter for the devkit errors.

jimAtLoyal commented 1 year ago

Since the LanguageServer is working, should this be closed and the Project issue reported elsewhere?

No global.json TFM is net7.0

> /usr/local/share/dotnet/x64/dotnet --version
7.0.305
> /usr/local/share/dotnet/dotnet --version
7.0.305
> dotnet sdk  check
.NET SDKs:
Version      Status
----------------------------------------
6.0.408      Patch 6.0.411 is available.
7.0.201      Patch 7.0.203 is available.
7.0.305      Up to date.

Try out the newest .NET SDK features with .NET 8.0.100-preview.5.23303.2.

.NET Runtimes:
Name                          Version      Status
---------------------------------------------------------------------
Microsoft.AspNetCore.App      6.0.16       Patch 6.0.19 is available.
Microsoft.NETCore.App         6.0.16       Patch 6.0.19 is available.
Microsoft.AspNetCore.App      7.0.3        Patch 7.0.8 is available.
Microsoft.NETCore.App         7.0.3        Patch 7.0.8 is available.
Microsoft.AspNetCore.App      7.0.8        Up to date.
jimAtLoyal commented 1 year ago

I happened to run code --version this morning, and even though I'm on an M1, it is say x64, if that makes any difference.

> code --version
1.80.0-insider
7406a9bdfca18f82a3977ba5eac908d41df7ccac
x64
JoeRobich commented 1 year ago

I've noticed that the universal VS Code install runs as x64 under Rosetta. It is a very interesting configuration you have. It might be worth a shot simply installing the apple silicon build of VS Code. https://code.visualstudio.com/download

jimAtLoyal commented 1 year ago

Still can't find a compatible SDK when running the arm version

> code --version
1.80.0-insider
660393deaaa6d1996740ff4880f1bad43768c814
arm64
JoeRobich commented 1 year ago

Sorry for all the back and forth on finding a solution. This shows we should do more testing with non-standard configurations.

I have to install the x64 version and alias dotnet to /usr/local/share/dotnet/x64/dotnet not the arm64.

Now that you have the arm64 VS Code and arm64 builds of the extensions installed. This seems to be the last bit that might be confusing things. Does it work if you remove the x64 dotnet alias?

justynhunter commented 1 year ago

I am running arm64 versions of .net 7 and vs code and get the same error.

I also have an intel Mac and everything works fine there.

dyzdyz010 commented 1 year ago

same issue here

wanghao522 commented 1 year ago

same issue here

Archanian commented 1 year ago

same here (running arm64 vscode, arm64 .net 7)

justynhunter commented 1 year ago

here some more from the C# dev kit output in vs code

Starting Open a solution...
Starting Open a solution with environment service...
Starting Clear environment...
Starting Spawn .NET server...
.NET server STDERR: Failed to load /Users/jhunter/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.9/host/fxr/7.0.9/libhostfxr.dylib, error: dlopen(/Users/jhunter/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.9/host/fxr/7.0.9/libhostfxr.dylib, 0x0001): tried: '/Users/jhunter/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.9/host/fxr/7.0.9/libhostfxr.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/jhunter/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.9/host/fxr/7.0.9/libhostfxr.dylib' (no such file), '/Users/jhunter/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.9/host/fxr/7.0.9/libhostfxr.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
The library libhostfxr.dylib was found, but loading it from /Users/jhunter/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.9/host/fxr/7.0.9/libhostfxr.dylib failed
  - Installing .NET prerequisites might help resolve this problem.
     https://go.microsoft.com/fwlink/?linkid=2063366

I think the important part is '/Users/jhunter/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.9/host/fxr/7.0.9/libhostfxr.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

wanghao522 commented 1 year ago

Dotnet path: /Users/haowang/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.10/dotnet Activating C# standalone... Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.LanguageServer, Version=4.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. [Error - 2:12:52 PM] Server initialization failed. Message: Pending response rejected since connection got disposed Code: -32097 [Info - 2:12:52 PM] Connection to server got closed. Server will restart. true [Error - 2:12:52 PM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server. Message: Pending response rejected since connection got disposed Code: -32097 Dotnet path: /Users/haowang/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.10/dotnet Activating C# standalone... Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.LanguageServer, Version=4.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. [Error - 2:12:53 PM] Server initialization failed. Message: Pending response rejected since connection got disposed Code: -32097 [Info - 2:12:53 PM] Connection to server got closed. Server will restart. true [Error - 2:12:53 PM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server. Message: Pending response rejected since connection got disposed Code: -32097 Dotnet path: /Users/haowang/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.10/dotnet Activating C# standalone... Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.LanguageServer, Version=4.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. [Error - 2:12:53 PM] Server initialization failed. Message: Pending response rejected since connection got disposed Code: -32097 [Info - 2:12:53 PM] Connection to server got closed. Server will restart. true [Error - 2:12:53 PM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server. Message: Pending response rejected since connection got disposed Code: -32097 [Error - 2:12:53 PM] Restarting server failed Message: Pending response rejected since connection got disposed Code: -32097 Dotnet path: /Users/haowang/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.10/dotnet Activating C# standalone... Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.LanguageServer, Version=4.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. [Error - 2:12:53 PM] Server initialization failed. Message: Pending response rejected since connection got disposed Code: -32097 [Info - 2:12:53 PM] Connection to server got closed. Server will restart. true [Error - 2:12:53 PM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server. Message: Pending response rejected since connection got disposed Code: -32097 [Error - 2:12:53 PM] Restarting server failed Message: Pending response rejected since connection got disposed Code: -32097 Dotnet path: /Users/haowang/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.10/dotnet Activating C# standalone... Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.LanguageServer, Version=4.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. [Error - 2:12:53 PM] Server initialization failed. Message: Pending response rejected since connection got disposed Code: -32097 [Error - 2:12:53 PM] The Microsoft.CodeAnalysis.LanguageServer server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information. [Error - 2:12:53 PM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server. Message: Pending response rejected since connection got disposed Code: -32097 [Error - 2:12:53 PM] Restarting server failed Message: Pending response rejected since connection got disposed Code: -32097

liaowenming23 commented 1 year ago

same issue, but I have .net 5 project run x64 version sdk.

dibarbet commented 1 year ago

We've made a few fixes in this area (for example loading dotnet from the path when available) and do have one more mac related fixes on the way.

To anyone encountering this issue - would you be able to try the latest versions of C# (and devkit if applicable)? If it still is not working, please attach the C# output window logs - there will hopefully be some additional log info there we can use.

Additionally - could you let me know if dotnet has been installed via homebrew?

jimAtLoyal commented 1 year ago

I got a new message in VSCode about not having the arm64 of dotnet. I installed it (in addition to existing x64, which I must have to build our app), and now I get these messages in the log. I installed arm64 via the installer, and think the same was true for x64, but it has been a while.

2023-09-06 07:55:06.635 [info] Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.VisualStudio.ProjectSystem.Server.BuildHost, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
[createdump] thread_get_state(7efd) FAILED (os/kern) invalid argument (4)
[createdump] Failure took 9ms

2023-09-06 07:55:11.161 [info] .NET SDK for X64 CPU may have been installed on an Apple computer with Apple CPU, which does not work with C# Dev Kit. Please uninstall it and reinstall SDK for ARM 64 platform before using C# Dev Kit. A reboot might be necessary after installing the new SDK.
2023-09-06 07:55:42.153 [info] Project system initialization finished. 0 project(s) are loaded, and 8 failed to load.
liaowenming23 commented 1 year ago

installed C# Dev kit 0.5.147 version, i got message from project window

2023-10-04 16:41:57.630 [info] Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.VisualStudio.ProjectSystem.Server.BuildHost, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

2023-10-04 16:41:57.650 [info] .NET SDK for X64 CPU may have been installed on an Apple computer with Apple CPU, which does not work with C# Dev Kit. Please uninstall it and reinstall SDK for ARM 64 platform before using C# Dev Kit. A reboot might be necessary after installing the new SDK.
2023-10-04 16:41:57.652 [info] [createdump] thread_get_state(322f) FAILED (os/kern) invalid argument (4)
[createdump] Failure took 29ms

and C# window output

[stderr] Unhandled exception. [stderr] System.IO.FileLoadException: Could not load file or assembly 'Microsoft.CodeAnalysis.LanguageServer, Version=4.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
[Error - 5:12:37 PM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server.
Error: Timeout. Named pipe information not received from server.
    at N.<anonymous> (/Users/wenming/.vscode/extensions/ms-dotnettools.csharp-2.4.4-darwin-arm64/dist/extension.js:2:1441424)
    at Generator.next (<anonymous>)
    at s (/Users/wenming/.vscode/extensions/ms-dotnettools.csharp-2.4.4-darwin-arm64/dist/extension.js:2:1431992)

dotnet info

.NET SDK:
 Version:   8.0.100-rc.1.23463.5
 Commit:    e7f4de8816

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.5
 OS Platform: Darwin
 RID:         osx-x64
 Base Path:   /usr/local/share/dotnet/x64/sdk/8.0.100-rc.1.23463.5/

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.0-rc.1.23419.4
  Architecture: x64
  Commit:       92959931a3
  RID:          osx-x64

.NET SDKs installed:
  5.0.407 [/usr/local/share/dotnet/x64/sdk]
  6.0.202 [/usr/local/share/dotnet/x64/sdk]
  6.0.411 [/usr/local/share/dotnet/x64/sdk]
  7.0.401 [/usr/local/share/dotnet/x64/sdk]
  8.0.100-rc.1.23463.5 [/usr/local/share/dotnet/x64/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.16 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.4 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.19 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.11 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0-rc.1.23421.29 [/usr/local/share/dotnet/x64/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.16 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.4 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.19 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.11 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0-rc.1.23419.4 [/usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App]

my mac was M1 chip, macOS 13.5.1

jimAtLoyal commented 1 year ago

Now that it is GA, any update? I re-enabled it today on my M1 and still get errors.

Failed to find dotnet info from path, falling back to acquire runtime via ms-dotnettools.vscode-dotnet-runtime
The architecture of the .NET runtime (x64) does not match the architecture of the extension (arm64).
Dotnet path: /Users/me/Library/Application Support/Code - Insiders/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.11~arm64/dotnet
Activating C# standalone...
waiting for named pipe information from server...
[Error - 9:01:27 AM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server.
Error: Timeout. Named pipe information not received from server.
    at Function.<anonymous> (/Users/me/.vscode-insiders/extensions/ms-dotnettools.csharp-2.5.30-darwin-arm64/dist/extension.js:2:1451003)
    at Generator.next (<anonymous>)
    at s (/Users/me/.vscode-insiders/extensions/ms-dotnettools.csharp-2.5.30-darwin-arm64/dist/extension.js:2:1441345)
dibarbet commented 1 year ago

@jimAtLoyal this is still on my radar, but we've been busy tackling a few high hitting issues. It looks like the error you're getting is a bit different now (we've changed a bunch of things in relation to process launch and dotnet discovery). I've not been able to reproduce this specific issue on my M1 (though I've encountered others in relation to project loading with both arm64 and x64 dotnet installed).

That error means that the client failed to connect to the process - generally that happens when the process fails to start, but that doesn't appear to be happening in this case. A couple requests

  1. If you haven't already, set dotnet.server.trace to Trace
  2. You can also provide a (user writeable) path in dotnet.server.crashDumpPath which will capture a dump if the process crashes (not sure if it is). If it does, please email it to me (listed in my github profile) and reference this issue.
  3. This is unlikely to fix it if the process is failing in some other way, but you can increase the time that the client waits for the process to start by changing the value of dotnet.server.startTimeout
  4. When it hits the timeout, is the server process running? Running ps -ef | grep Microsoft.CodeAnalysis.LanguageServer should show you something if its running.
dibarbet commented 1 year ago

One more thing - can you share the output of where dotnet and include the original path if they are symlinks (via readlink <path from where>)?

jimAtLoyal commented 1 year ago

Thanks for the update.

I set the three values you mentioned in my VSCode settings.

    "dotnet.server.trace": "Trace",
    "dotnet.server.crashDumpPath": "/var/folders/wt/48syr7hn5qs3qw_vbs0gl3l00000gn/T/vscodeump", # TMPDIR/vscodedump
    "dotnet.server.startTimeout": 30000
~ » where dotnet
/usr/local/share/dotnet/x64/dotnet
/usr/local/share/dotnet/dotnet
/opt/homebrew/bin/dotnet

~ » ls -la /opt/homebrew/bin/dotnet
lrwxr-xr-x  1 me  admin  30 Feb 27  2023 /opt/homebrew/bin/dotnet -> /usr/local/share/dotnet/dotnet
~ » ls -la /usr/local/share/dotnet/x64/dotnet
-rwxr-xr-x  1 root  wheel  147744 Jun 19 15:16 /usr/local/share/dotnet/x64/dotnet
~ » ls -la /usr/local/share/dotnet/dotnet
-rwxr-xr-x  1 root  wheel  163216 Jul 21 18:20 /usr/local/share/dotnet/dotnet

I restarted and got this in the log, but nothing in the dump folder. There is an invalid argument message. Quite a few mainly empty files get created in $TMPDIR

2023-10-10 07:19:46.659 [info] Unhandled exception. System.IO.FileLoadException: Could not load file or assembly 'Microsoft.VisualStudio.ProjectSystem.Server.BuildHost, Version=17.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
[createdump] thread_get_state(172e6) FAILED (os/kern) invalid argument (4)
[createdump] Failure took 8ms

2023-10-10 07:19:46.971 [info] .NET SDK for X64 CPU may have been installed on an Apple computer with Apple CPU, which does not work with C# Dev Kit. Please uninstall it and reinstall SDK for ARM 64 platform before using C# Dev Kit. A reboot might be necessary after installing the new SDK.
2023-10-10 07:19:49.046 [info] Project system initialization finished. 0 project(s) are loaded, and 9 failed to load.

And ps

ps -ef | grep Microsoft.CodeAnalysis.LanguageServer
  501 15996 15900   0  7:19AM ??         0:05.32 /Users/me/Library/Application Support/Code - Insiders/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/7.0.11~arm64/dotnet /Users/me/.vscode-insiders/extensions/ms-dotnettools.csharp-2.5.30-darwin-arm64/.roslyn/Microsoft.CodeAnalysis.LanguageServer.dll --logLevel Trace --starredCompletionComponentPath /Users/me/.vscode-insiders/extensions/ms-dotnettools.vscodeintellicode-csharp-0.1.26-darwin-arm64/components/starred-suggestions/node_modules/@vsintellicode/starred-suggestions-csharp --sharedDependencies /Users/me/.vscode-insiders/extensions/ms-dotnettools.csdevkit-0.5.150-darwin-arm64/components/vs-green-server/platforms/darwin-arm64/node_modules/@microsoft/visualstudio-server-shared.darwin-arm64 --extension /Users/me/.vscode-insiders/extensions/ms-dotnettools.csdevkit-0.5.150-darwin-arm64/components/roslyn-visualstudio-languageservices-devkit/node_modules/@microsoft/visualstudio-languageservices-devkit/Microsoft.VisualStudio.LanguageServices.DevKit.dll --sessionId 482b3a75-5560-444e-9130-757c49e00c861696936782289 --telemetryLevel all --extensionLogDirectory /Users/me/Library/Application Support/Code - Insiders/logs/20231010T071941/window1/exthost/ms-dotnettools.csharp
dibarbet commented 11 months ago

So this is where I'm at

  1. The dotnet on the path is the x64 version of dotnet. The server therefore falls back to the dotnet runtime download because it requires arm64.
  2. For some reason - the server is crashing when running against the arm64 runtime it downloaded. I'm not sure why this is happening - I haven't been able to reproduce this. It might be a corrupt installation.
  3. Collecting the crash dump appears to be failing. Pretty sure this is because dotnet-dump is running using the x64 dotnet on the path - and dotnet-dump does not support collecting dumps on the Rosetta emulation (see https://github.com/dotnet/runtime/issues/90938)

I have two things you can try. The first is to reorder which SDK architectures are on your path to ensure that VSCode starts with the $PATH pointing to the arm64 version of dotnet. First make sure VSCode is entirely closed (not just minimized). Then, edit your shell profile to ensure the arm64 version is ahead of the x64 version of dotnet. I was able to do this via editing my .zshrc file (since I'm on a zsh shell) to look something like:

export PATH="/usr/local/share/dotnet:/usr/local/share/x64:$PATH"

This ensures that the arm64 dotnet installation is seen on the path before the x64 version. My where output looks kind of weird after with multiple of the same thing in the path, but importantly the arm64 path is at the top

dabarbet@Davids-MacBook-Pro ~ % where dotnet
/usr/local/share/dotnet/dotnet
/usr/local/share/dotnet/x64/dotnet
/usr/local/share/dotnet/x64/dotnet
/usr/local/share/dotnet/dotnet
/usr/local/share/dotnet/x64/dotnet

Then running source ~/.zshrc and code <my repo> should cause the server to pick up the arm64 version of dotnet and you'll see this line in the output window which points to the arm64 dotnet.

Dotnet path: /usr/local/share/dotnet/dotnet

If that doesn't help at all, then I would try the following

  1. Completely remove all existing dotnet installations (if you installed via homebrew, uninstall that as well). Basically you want /usr/local/share/dotnet to not exist, and remove anything configuring a dotnet path from your environment variables in your profile. See also https://learn.microsoft.com/en-us/dotnet/core/install/remove-runtime-sdk-versions?pivots=os-macos
  2. At this point dotnet --info and where dotnet should not work
  3. Delete everything in /Users/<User>/Library/Application Support/Code - Insiders/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/
  4. Install only the arm64 dotnet SDK and check if you are able to open a project successfully with VSCode.
  5. Install an x64 SDK (if you need it), and verify that you're able to open a project successfully.
jimAtLoyal commented 11 months ago

Thanks. Setting the path before launching code fixed it! "It's always easy when you know the answer"

And during this process I found by upgrading the Confluent NuGet, I no longer need the x64 version.