dotnet / vscode-csharp

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

InvalidOperationException: Unexpected null when writing top level console app with .NET 6 SDK #4460

Open danroth27 opened 3 years ago

danroth27 commented 3 years ago

Issue Description

Steps to Reproduce

Expected Behavior

Code action offered to add using System; No exceptions in the Omnisharp logs.

Actual Behavior

No code action offered to add missing using directive. Exception in Omnisharp log: InvalidOperationException: Unexpected null

Logs

OmniSharp log

Starting OmniSharp server at 3/26/2021, 8:20:57 AM Target: c:\Users\daroth\Desktop\ConsoleApp1

OmniSharp server started. Path: c:\Users\daroth.vscode\extensions\ms-dotnettools.csharp-1.23.9.omnisharp\1.37.6\OmniSharp.exe PID: 4720

    Starting OmniSharp on Windows 6.2.9200.0 (x64)
    DotNetPath set to dotnet
    Located 5 MSBuild instance(s)
        1: Visual Studio Enterprise 2019 16.10.31025.218 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\Bin"
        2: Visual Studio Enterprise 2019 16.9.31112.23 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin"
        3: Visual Studio Enterprise 2019 16.10.31123.337 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\IntPreview\MSBuild\Current\Bin"
        4: Visual Studio Build Tools 2017 15.9.28307.1401 - "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
        5: StandAlone 16.8.0 - "c:\Users\daroth\.vscode\extensions\ms-dotnettools.csharp-1.23.9\.omnisharp\1.37.6\.msbuild\Current\Bin"
    Registered MSBuild instance: Visual Studio Enterprise 2019 16.10.31123.337 - "C:\Program Files (x86)\Microsoft Visual Studio\2019\IntPreview\MSBuild\Current\Bin"
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpFormattingWorkspaceOptionsProvider, Order: 0
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.Completion.CompletionOptionsProvider, Order: 0
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.RenameWorkspaceOptionsProvider, Order: 100
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.ImplementTypeWorkspaceOptionsProvider, Order: 110
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.BlockStructureWorkspaceOptionsProvider, Order: 140
    Detecting Cake files in 'c:\Users\daroth\Desktop\ConsoleApp1'.
    Could not find any Cake files
    No solution files found in 'c:\Users\daroth\Desktop\ConsoleApp1'
    Queue project update for 'c:\Users\daroth\Desktop\ConsoleApp1\ConsoleApp1.csproj'
    Detecting CSX files in 'c:\Users\daroth\Desktop\ConsoleApp1'.
    Could not find any CSX files
    Configuration finished.
    Omnisharp server running using Stdio at location 'c:\Users\daroth\Desktop\ConsoleApp1' on host 8084.
    Loading project: c:\Users\daroth\Desktop\ConsoleApp1\ConsoleApp1.csproj
    Successfully loaded project file 'c:\Users\daroth\Desktop\ConsoleApp1\ConsoleApp1.csproj'.
    Adding project 'c:\Users\daroth\Desktop\ConsoleApp1\ConsoleApp1.csproj'
    Update project: ConsoleApp1
    ************ Request ************

{ "Type": "request", "Seq": 21, "Command": "/findusages", "Arguments": { "FileName": "c:\Users\daroth\Desktop\ConsoleApp1\Program.cs", "Line": 0, "Column": 0, "OnlyThisFile": true, "ExcludeDefinition": false } }

    ************  Response ************ 

{ "Request_seq": 21, "Command": "/findusages", "Running": true, "Success": false, "Message": "\"System.InvalidOperationException: Unexpected null\r\n at Roslyn.Utilities.Contract.Fail(String message)\r\n at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.MapToAppropriateSymbol(ISymbol symbol)\r\n at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.d20.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.d19.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.d8.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.d8.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Microsoft.CodeAnalysis.FindSymbols.FindReferencesSearchEngine.d8.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.d34.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.d40.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.d39.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at OmniSharp.Roslyn.CSharp.Services.Navigation.FindUsagesService.d2.MoveNext() in D:\\a\\1\\s\\src\\OmniSharp.Roslyn.CSharp\\Services\\Navigation\\FindUsagesService.cs:line 41\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at OmniSharp.Endpoint.EndpointHandler`2.d18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at OmniSharp.Endpoint.EndpointHandler2.<HandleRequestForLanguage>d__20.MoveNext() in D:\\\\a\\\\1\\\\s\\\\src\\\\OmniSharp.Host\\\\Endpoint\\\\EndpointHandler.cs:line 227\\r\\n--- End of stack trace from previous location where exception was thrown ---\\r\\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\\r\\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\\r\\n at OmniSharp.Endpoint.EndpointHandler2.d16.MoveNext() in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 131\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at OmniSharp.Stdio.Host.d13.MoveNext() in D:\\a\\1\\s\\src\\OmniSharp.Stdio\\Host.cs:line 215\"", "Body": null, "Seq": 128, "Type": "response" }

C# log

[No output]

Environment information

VSCode version: 1.54.3 C# Extension: 1.23.9

Dotnet Information .NET SDK (reflecting any global.json): Version: 6.0.100-preview.3.21176.3 Commit: 89f2987f74 Runtime Environment: OS Name: Windows OS Version: 10.0.19042 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\6.0.100-preview.3.21176.3\ Host (useful for support): Version: 6.0.0-preview.3.21167.1 Commit: 0f64b267ac .NET SDKs installed: 3.1.407 [C:\Program Files\dotnet\sdk] 5.0.104 [C:\Program Files\dotnet\sdk] 5.0.200-preview.21077.7 [C:\Program Files\dotnet\sdk] 5.0.200 [C:\Program Files\dotnet\sdk] 5.0.201 [C:\Program Files\dotnet\sdk] 6.0.100-preview.3.21176.3 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.All 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.0-preview.3.21172.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.23 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.0-preview.3.21167.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.0-preview.3.21172.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions |Extension|Author|Version| |---|---|---| |azure-account|ms-vscode|0.9.7| |code-spell-checker|streetsidesoftware|1.10.2| |csharp|ms-dotnettools|1.23.9| |dart-code|Dart-Code|3.20.1| |flutter|Dart-Code|3.20.0| |javascript-ejs-support|DigitalBrainstem|1.3.1| |LiveServer|ritwickdey|5.6.1| |remote-wsl|ms-vscode-remote|0.54.6| |vscode-azureappservice|ms-azuretools|0.21.2| |vscode-azureresourcegroups|ms-azuretools|0.3.0| |WebTemplateStudio-dev-nightly|WASTeamAccount|0.5.2104801|;
filipw commented 3 years ago

I don't think this is related to Preview 3. There is an (unfortunately) known issue with the client and server getting out of sync which manifests itself this way (basically line numbers in the editor don't match the server state). see e.g. the discussion here https://github.com/OmniSharp/omnisharp-vscode/issues/4307#issuecomment-766874460 it often happens when you start editing without the project being fully loades yet

this has been introduced in recent versions of the extension and we think moving to LSP will improve stability and consistency.

a restart normally fixes this.

danroth27 commented 3 years ago

a restart normally fixes this.

Just restart VS Code? Or do you mean the whole machine?

filipw commented 3 years ago

OmniSharp restart (there is a command for this) which can also be achieved simply by a VS Code restart

danroth27 commented 3 years ago

Restarting VS Code and Omnisharp doesn't seem to help in this case. I've also tried waiting until it looks like things have loaded in the Omnisharp logs before starting to edit. This repros reliably for me.

filipw commented 3 years ago

Yeah but the exception you shared is not related to code actions - it comes from find references and is triggered via code lense, so it sounds like we are mixing up two things here. What I understand you are opening this because you don't get the expected code action, and this exception is likely only clouding the picture and perhaps your root cause is different.

Does other stuff work correctly e.g. intellisense or navigation?

filipw commented 3 years ago

Perhaps you can capture all the logs by setting "omnisharp.loggingLevel":"debug"

FWIW this is what I see, albeit on a Mac

Bildschirmfoto 2021-03-26 um 20 00 10
danroth27 commented 3 years ago

omnisharp-log.log

danroth27 commented 3 years ago

Other stuff does seem to work:

image