dotnet / vscode-csharp

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

Language server won't start with custom dotnet path #6068

Closed dandev486 closed 1 year ago

dandev486 commented 1 year ago

Type: Bug

Issue Description

Language server won't start with custom dotnet path configured through dotnet.dotnetPath setting.

Steps to Reproduce

  1. Install the extension C# v2.0.328

  2. Explicitly configure dotnet path on VSCode settings file, for instance.

    "dotnet.dotnetPath": "/usr/bin/",
  3. Create a console application and solution file

    dotnet new console --name Project --output .
    dotnet new sln --name Project --output .
    dotnet sln add .
  4. Check the logs

Expected Behavior

No errors and the language server launches, providing completion, refactoring, etc.

Actual Behavior

Language server does not launch properly, logs contain messages regarding a missing installation (which is not the case, since I have installed both .NET SDK 6x and .NET SDK 7x), for instance:

.NET location: Not found
You must install .NET to run this application.

Logs

C# log

Dotnet path: /usr/bin/dotnet
Activating C# standalone...
You must install .NET to run this application.

App: /home/dandev486/.vscode/extensions/ms-dotnettools.csharp-2.0.328-linux-x64/.roslyn/Microsoft.CodeAnalysis.LanguageServer
Architecture: x64
App host version: 7.0.0-preview.7.22362.8
.NET location: Not found

Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=debian.12-x64&apphost_version=7.0.0-preview.7.22362.8
[Error - 5:59:39 AM] Server initialization failed.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 5:59:39 AM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Info  - 5:59:39 AM] Connection to server got closed. Server will restart.
true
Dotnet path: /usr/bin/dotnet
Activating C# standalone...
You must install .NET to run this application.

App: /home/dandev486/.vscode/extensions/ms-dotnettools.csharp-2.0.328-linux-x64/.roslyn/Microsoft.CodeAnalysis.LanguageServer
Architecture: x64
App host version: 7.0.0-preview.7.22362.8
.NET location: Not found

Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=debian.12-x64&apphost_version=7.0.0-preview.7.22362.8
[Error - 5:59:39 AM] Server initialization failed.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 5:59:39 AM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 5:59:39 AM] Restarting server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Info  - 5:59:39 AM] Connection to server got closed. Server will restart.
true
Dotnet path: /usr/bin/dotnet
Activating C# standalone...
You must install .NET to run this application.

App: /home/dandev486/.vscode/extensions/ms-dotnettools.csharp-2.0.328-linux-x64/.roslyn/Microsoft.CodeAnalysis.LanguageServer
Architecture: x64
App host version: 7.0.0-preview.7.22362.8
.NET location: Not found

Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=debian.12-x64&apphost_version=7.0.0-preview.7.22362.8
[Error - 5:59:39 AM] Server initialization failed.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 5:59:39 AM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 5:59:39 AM] Restarting server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Info  - 5:59:39 AM] Connection to server got closed. Server will restart.
true
Dotnet path: /usr/bin/dotnet
Activating C# standalone...
You must install .NET to run this application.

App: /home/dandev486/.vscode/extensions/ms-dotnettools.csharp-2.0.328-linux-x64/.roslyn/Microsoft.CodeAnalysis.LanguageServer
Architecture: x64
App host version: 7.0.0-preview.7.22362.8
.NET location: Not found

Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=debian.12-x64&apphost_version=7.0.0-preview.7.22362.8
[Error - 5:59:39 AM] Server initialization failed.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 5:59:39 AM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server.
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Error - 5:59:39 AM] Restarting server failed
  Message: Cannot call write after a stream was destroyed
  Code: -32099 
[Info  - 5:59:39 AM] Connection to server got closed. Server will restart.
true
Dotnet path: /usr/bin/dotnet
Activating C# standalone...
You must install .NET to run this application.

App: /home/dandev486/.vscode/extensions/ms-dotnettools.csharp-2.0.328-linux-x64/.roslyn/Microsoft.CodeAnalysis.LanguageServer
Architecture: x64
App host version: 7.0.0-preview.7.22362.8
.NET location: Not found

Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=debian.12-x64&apphost_version=7.0.0-preview.7.22362.8
[Error - 5:59:39 AM] Client Microsoft.CodeAnalysis.LanguageServer: connection to server is erroring. Shutting down server.
[Error - 5:59:39 AM] Stopping server failed
Error: Client is not running and can't be stopped. It's current state is: starting
    at s.shutdown (/home/dandev486/.vscode/extensions/ms-dotnettools.csharp-2.0.328-linux-x64/dist/extension.js:2:2237784)
    at s.stop (/home/dandev486/.vscode/extensions/ms-dotnettools.csharp-2.0.328-linux-x64/dist/extension.js:2:2237365)
    at s.stop (/home/dandev486/.vscode/extensions/ms-dotnettools.csharp-2.0.328-linux-x64/dist/extension.js:2:2400537)
    at s.handleConnectionError (/home/dandev486/.vscode/extensions/ms-dotnettools.csharp-2.0.328-linux-x64/dist/extension.js:2:2243872)
    at process.processTicksAndRejections (node:internal/process/task_queues:96:5)
[Error - 5:59:39 AM] Server initialization failed.
  Message: write EPIPE
  Code: -32099 
[Error - 5:59:39 AM] Microsoft.CodeAnalysis.LanguageServer client: couldn't create connection to server.
  Message: write EPIPE
  Code: -32099 
[Error - 5:59:39 AM] Restarting server failed
  Message: write EPIPE
  Code: -32099 
[Error - 5:59:39 AM] 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.

C# LSP Trace Logs

Extension vscode.bat does not contribute csharpExtensionLoadPaths
Extension vscode.clojure does not contribute csharpExtensionLoadPaths
Extension vscode.coffeescript does not contribute csharpExtensionLoadPaths
Extension vscode.configuration-editing does not contribute csharpExtensionLoadPaths
Extension vscode.cpp does not contribute csharpExtensionLoadPaths
Extension vscode.csharp does not contribute csharpExtensionLoadPaths
Extension vscode.css does not contribute csharpExtensionLoadPaths
Extension vscode.css-language-features does not contribute csharpExtensionLoadPaths
Extension vscode.dart does not contribute csharpExtensionLoadPaths
Extension vscode.debug-auto-launch does not contribute csharpExtensionLoadPaths
Extension vscode.debug-server-ready does not contribute csharpExtensionLoadPaths
Extension vscode.diff does not contribute csharpExtensionLoadPaths
Extension vscode.docker does not contribute csharpExtensionLoadPaths
Extension vscode.emmet does not contribute csharpExtensionLoadPaths
Extension vscode.extension-editing does not contribute csharpExtensionLoadPaths
Extension vscode.fsharp does not contribute csharpExtensionLoadPaths
Extension vscode.git does not contribute csharpExtensionLoadPaths
Extension vscode.git-base does not contribute csharpExtensionLoadPaths
Extension vscode.github does not contribute csharpExtensionLoadPaths
Extension vscode.github-authentication does not contribute csharpExtensionLoadPaths
Extension vscode.go does not contribute csharpExtensionLoadPaths
Extension vscode.groovy does not contribute csharpExtensionLoadPaths
Extension vscode.grunt does not contribute csharpExtensionLoadPaths
Extension vscode.gulp does not contribute csharpExtensionLoadPaths
Extension vscode.handlebars does not contribute csharpExtensionLoadPaths
Extension vscode.hlsl does not contribute csharpExtensionLoadPaths
Extension vscode.html does not contribute csharpExtensionLoadPaths
Extension vscode.html-language-features does not contribute csharpExtensionLoadPaths
Extension vscode.ini does not contribute csharpExtensionLoadPaths
Extension vscode.ipynb does not contribute csharpExtensionLoadPaths
Extension vscode.jake does not contribute csharpExtensionLoadPaths
Extension vscode.java does not contribute csharpExtensionLoadPaths
Extension vscode.javascript does not contribute csharpExtensionLoadPaths
Extension vscode.json does not contribute csharpExtensionLoadPaths
Extension vscode.json-language-features does not contribute csharpExtensionLoadPaths
Extension vscode.julia does not contribute csharpExtensionLoadPaths
Extension vscode.latex does not contribute csharpExtensionLoadPaths
Extension vscode.less does not contribute csharpExtensionLoadPaths
Extension vscode.log does not contribute csharpExtensionLoadPaths
Extension vscode.lua does not contribute csharpExtensionLoadPaths
Extension vscode.make does not contribute csharpExtensionLoadPaths
Extension vscode.markdown does not contribute csharpExtensionLoadPaths
Extension vscode.markdown-language-features does not contribute csharpExtensionLoadPaths
Extension vscode.markdown-math does not contribute csharpExtensionLoadPaths
Extension vscode.media-preview does not contribute csharpExtensionLoadPaths
Extension vscode.merge-conflict does not contribute csharpExtensionLoadPaths
Extension vscode.microsoft-authentication does not contribute csharpExtensionLoadPaths
Extension ms-vscode.js-debug does not contribute csharpExtensionLoadPaths
Extension ms-vscode.js-debug-companion does not contribute csharpExtensionLoadPaths
Extension ms-vscode.vscode-js-profile-table does not contribute csharpExtensionLoadPaths
Extension vscode.builtin-notebook-renderers does not contribute csharpExtensionLoadPaths
Extension vscode.npm does not contribute csharpExtensionLoadPaths
Extension vscode.objective-c does not contribute csharpExtensionLoadPaths
Extension vscode.perl does not contribute csharpExtensionLoadPaths
Extension vscode.php does not contribute csharpExtensionLoadPaths
Extension vscode.php-language-features does not contribute csharpExtensionLoadPaths
Extension vscode.powershell does not contribute csharpExtensionLoadPaths
Extension vscode.pug does not contribute csharpExtensionLoadPaths
Extension vscode.python does not contribute csharpExtensionLoadPaths
Extension vscode.r does not contribute csharpExtensionLoadPaths
Extension vscode.razor does not contribute csharpExtensionLoadPaths
Extension vscode.references-view does not contribute csharpExtensionLoadPaths
Extension vscode.restructuredtext does not contribute csharpExtensionLoadPaths
Extension vscode.ruby does not contribute csharpExtensionLoadPaths
Extension vscode.rust does not contribute csharpExtensionLoadPaths
Extension vscode.scss does not contribute csharpExtensionLoadPaths
Extension vscode.search-result does not contribute csharpExtensionLoadPaths
Extension vscode.shaderlab does not contribute csharpExtensionLoadPaths
Extension vscode.shellscript does not contribute csharpExtensionLoadPaths
Extension vscode.simple-browser does not contribute csharpExtensionLoadPaths
Extension vscode.sql does not contribute csharpExtensionLoadPaths
Extension vscode.swift does not contribute csharpExtensionLoadPaths
Extension vscode.theme-abyss does not contribute csharpExtensionLoadPaths
Extension vscode.theme-defaults does not contribute csharpExtensionLoadPaths
Extension vscode.theme-kimbie-dark does not contribute csharpExtensionLoadPaths
Extension vscode.theme-monokai does not contribute csharpExtensionLoadPaths
Extension vscode.theme-monokai-dimmed does not contribute csharpExtensionLoadPaths
Extension vscode.theme-quietlight does not contribute csharpExtensionLoadPaths
Extension vscode.theme-red does not contribute csharpExtensionLoadPaths
Extension vscode.vscode-theme-seti does not contribute csharpExtensionLoadPaths
Extension vscode.theme-solarized-dark does not contribute csharpExtensionLoadPaths
Extension vscode.theme-solarized-light does not contribute csharpExtensionLoadPaths
Extension vscode.theme-tomorrow-night-blue does not contribute csharpExtensionLoadPaths
Extension vscode.typescript does not contribute csharpExtensionLoadPaths
Extension vscode.typescript-language-features does not contribute csharpExtensionLoadPaths
Extension vscode.vb does not contribute csharpExtensionLoadPaths
Extension vscode.xml does not contribute csharpExtensionLoadPaths
Extension vscode.yaml does not contribute csharpExtensionLoadPaths
Extension akamud.vscode-theme-onedark does not contribute csharpExtensionLoadPaths
Extension akamud.vscode-theme-onelight does not contribute csharpExtensionLoadPaths
Extension ms-dotnettools.csharp does not contribute csharpExtensionLoadPaths
Extension ms-dotnettools.vscode-dotnet-runtime does not contribute csharpExtensionLoadPaths
Extension ms-vscode.cpptools does not contribute csharpExtensionLoadPaths

Environment information

VSCode version: 1.81.0 C# Extension: 2.0.328 Using OmniSharp: false

Dotnet Information .NET SDK: Version: 7.0.306 Commit: f500069cb7 Runtime Environment: OS Name: debian OS Version: 12 OS Platform: Linux RID: debian.12-x64 Base Path: /usr/share/dotnet/sdk/7.0.306/ Host: Version: 7.0.9 Architecture: x64 Commit: 8e9a17b221 .NET SDKs installed: 6.0.412 [/usr/share/dotnet/sdk] 7.0.306 [/usr/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.20 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.20 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.9 [/usr/share/dotnet/shared/Microsoft.NETCore.App] Other architectures found: None Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download
Visual Studio Code Extensions |Extension|Author|Version|Folder Name| |---|---|---|---| |cpptools|ms-vscode|1.16.3|ms-vscode.cpptools-1.16.3-linux-x64| |csharp|ms-dotnettools|2.0.328|ms-dotnettools.csharp-2.0.328-linux-x64| |vscode-dotnet-runtime|ms-dotnettools|1.6.0|ms-dotnettools.vscode-dotnet-runtime-1.6.0| |vscode-theme-onedark|akamud|2.3.0|akamud.vscode-theme-onedark-2.3.0| |vscode-theme-onelight|akamud|2.3.0|akamud.vscode-theme-onelight-2.3.0|;

Extension version: 2.0.328 VS Code version: Code 1.81.0 (6445d93c81ebe42c4cbd7a60712e0b17d9463e97, 2023-08-02T12:36:11.334Z) OS version: Linux x64 6.1.0-10-amd64 Modes:

dibarbet commented 1 year ago

From the dotnet info on the issue it looks like your .net7 SDK is installed in /usr/share/dotnet

.NET SDKs installed: 6.0.412 [/usr/share/dotnet/sdk] 7.0.306 [/usr/share/dotnet/sdk]

If you set the dotnet path to that does it work? Do you have an additional dotnet installation in /usr/bin/?

dandev486 commented 1 year ago

@dibarbet, is this setting then intented to point to the actual sdk installation directory and not to the directory where the symlink to dotnet is?

$ which dotnet
/usr/bin/dotnet
$ ls -lh /usr/bin/dotnet
lrwxrwxrwx 1 root root 22 Jun 20 16:43 /usr/bin/dotnet -> ../share/dotnet/dotnet
$ ls -lh /usr/share/dotnet/dotnet
-rwxr-xr-x 1 root root 143K Jun 20 16:43 /usr/share/dotnet/dotnet
dandev486 commented 1 year ago

In time, thanks for pointing that out, it works properly when set to /usr/share/dotnet/, even though my original expectation was that it would suffice to point to the directory where the symbolic link is.

Dotnet path: /usr/share/dotnet/dotnet
Activating C# standalone...
info: LanguageServerHost[0]
      Starting server...

[...]

[Info  - 8:24:18 PM] [LanguageServerProjectSystem]
Completed (re)load of all projects in 00:00:00.9406406
dibarbet commented 1 year ago

Ah /usr/bin/dotnet is symlinked, that's useful info. Not sure if that is expected to work, I'll take a look.

dandev486 commented 1 year ago

In case of this being relevant, the symlink is the one created by the package installation by following the installation instructions (surely, changing '11' to '12' for Debian Bookworm), and not a result of a custom setup of some sort.

dibarbet commented 1 year ago

Ah ok I think I just understood what is going on. The problem is that only the dotnet executable is symlinked.

While /usr/bin/dotnet (an executable) is symlinked to /usr/share/dotnet/dotnet (an executable), the dotnet path option is required to point to the folder containing the runtimes. That folder is /usr/share/dotnet and /usr/bin/ is not symlinked to it. So when you specified /usr/bin/ as the dotnet path it wasn't able to resolve any runtimes.

The takeaway here is that the dotnetPath option needs to point to the folder containing the dotnet installation. Symlinks will also work as long as the symlink points to the folder containing the dotnet installation (not just a link to the dotnet executable).

dandev486 commented 1 year ago

@dibarbet, thanks for the explanation. In case of being of interest this is my proposal for this thread.