dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.85k stars 670 forks source link

System.CommandLine Not Found & Causes LSP Server to Crash #7296

Closed libdev-hacker closed 2 months ago

libdev-hacker commented 3 months ago

Environment data

dotnet --info output: .NET SDK: Version: 8.0.301 Commit: 1a0e9c0300 Workload version: 8.0.300-manifests.f6879a9a MSBuild version: 17.10.4+10fbfbf2e

Runtime Environment: OS Name: ubuntu OS Version: 22.04 OS Platform: Linux RID: linux-x64 Base Path: /usr/share/dotnet/sdk/8.0.301/

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

Host: Version: 8.0.6 Architecture: x64 Commit: 3b8b000a0e

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

.NET runtimes installed: Microsoft.AspNetCore.App 8.0.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.6 [/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

VS Code version: 1.90.2

C# Extension version: v2.36.19 (pre-release)

Steps to reproduce

  1. Install C# Dev Kit
  2. Allow LSP to start up & see if it crashes

Expected behavior

The C# LSP server starts up & allows all accompanying extensions (Intellicode) to function properly

Actual behavior

The server crashes with the error:

Additional context

I have tried clearing all the extension's files but lead nowhere. Original problem was Solution Explorer not working but this has since been resolved by re-installing packages & manually setting path to LSP Server in settings.json

dibarbet commented 3 months ago

Interesting, we should be shipping System.CommandLine in the extension so it shouldn't be tearing. A couple requests @libdev-hacker

  1. You mentioned you cleared all the extension files - did you do that for both C# and C# devkit, or just devkit? If not please do that - first uninstall the extension, then close VSCode and delete both any ms-dotnettools.csharp-<version>-<platform> and ms-dotnettools.csdevkit-<version>-<platform> inside the VSCode extensions folder.

  2. If that doesn't work, once you have reinstalled could you take a look at the System.CommandLine.dll in <extensions folder>/ms-dotnettools.csharp-<version>-<platform>/.roslyn folder with something like ILSpy and let me know the assembly version info? E.g.

    image

  3. If you could turn on trace logging (set dotnet.server.trace to Trace in vscode settings and reload the window), and attach here or send me (email in my profile) the contents of the 'C#' output window?

libdev-hacker commented 2 months ago

I tried re-installing the extensions, like you suggested, but it still threw the same error as before.

ILSpy returned this for ~/.vscode-server/extensions/ms-dotnettools.csharp-2.34.12-linux-x64/.roslyn/System.CommandLine.dll: // System.CommandLine, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 // Global type: // Architecture: 64797 // This assembly contains unmanaged code. // Runtime: v4.0.30319 // This assembly is signed with a strong name key. // This assembly was compiled using the /deterministic option. // Hash algorithm: SHA1 // Public key: 0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9

Then the dotnet trace returned this: Using dotnet configured on PATH Dotnet path: /usr/lib/dotnet/dotnet Activating C# + C# Dev Kit... Starting server at ~/.vscode-server/extensions/ms-dotnettools.csdevkit-1.8.14-linux-x64/components/vs-green-server/platforms/linux-x64/node_modules/@microsoft/visualstudio-server.linux-x64/Microsoft.VisualStudio.Code.Server Server arguments --logLevel Trace --razorSourceGenerator ~/.vscode-server/extensions/ms-dotnettools.csharp-2.34.12-linux-x64/.razor/Microsoft.CodeAnalysis.Razor.Compiler.dll --razorDesignTimePath ~/.vscode-server/extensions/ms-dotnettools.csharp-2.34.12-linux-x64/.razor/Targets/Microsoft.NET.Sdk.Razor.DesignTime.targets --devKitDependencyPath ~/.vscode-server/extensions/ms-dotnettools.csharp-2.34.12-linux-x64/.roslynDevKit/Microsoft.VisualStudio.LanguageServices.DevKit.dll --sessionId bb6717ea-3f23-4d5f-9f19-135d02e68b231720622412447 --extension ~/.vscode-server/extensions/ms-dotnettools.csharp-2.34.12-linux-x64/.xamlTools/Microsoft.VisualStudio.DesignTools.CodeAnalysis.dll --extension ~/.vscode-server/extensions/ms-dotnettools.csharp-2.34.12-linux-x64/.xamlTools/Microsoft.VisualStudio.DesignTools.CodeAnalysis.Diagnostics.dll --telemetryLevel all --extensionLogDirectory ~/.vscode-server/data/logs/20240710T152035/exthost2/ms-dotnettools.csharp waiting for named pipe information from server... [stderr] Unhandled exception. Language server process exited with null [stderr] System.IO.FileNotFoundException: Could not load file or assembly 'System.CommandLine, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

File name: 'System.CommandLine, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' at Microsoft.VisualStudio.Server.ServiceBroker.Program.BuildCommandLine at Microsoft.VisualStudio.Server.ServiceBroker.Program.Main(String[] args) at Microsoft.VisualStudio.Server.ServiceBroker.Program.

(String[] args)

dibarbet commented 2 months ago

@libdev-hacker I think this line is indicating the issue - it looks like somehow the C# extension is attempting to launch the C# Dev Kit extension's server? That would definitely fail.

Starting server at ~/.vscode-server/extensions/ms-dotnettools.csdevkit-1.8.14-linux-x64/components/vs-green-server/platforms/linux-x64/node_modules/@microsoft/visualstudio-server.linux-x64/Microsoft.VisualStudio.Code.Server

Do you by chance have the dotnet.server.path setting modified in vscode settings? If so, please clear it out and reload.

libdev-hacker commented 2 months ago

Thanks for the help. I reset the path & now the LSP server works.

I have no idea when I set it to that or why but thanks for spotting my mistake.