OmniSharp / omnisharp-roslyn

OmniSharp server (HTTP, STDIO) based on Roslyn workspaces
MIT License
1.79k stars 420 forks source link

Fix all issues command in VSCode fails with System.NullReferenceException #2336

Open kevingeorget opened 2 years ago

kevingeorget commented 2 years ago

Hello,

I cannot use Omnisharp "Fix all issues" action in VSCode.

It causes this error : "System.NullReferenceException: Object reference not set to an instance of an object\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.FixSpecificDiagnosticIdAsync (Microsoft.CodeAnalysis.Document document, System.String diagnosticId, OmniSharp.Abstractions.Models.V1.FixAll.FixAllScope scope, System.Threading.CancellationToken cancellationToken) [0x002cd] in <7833e4dfb11c41969fc8bb341c494975>:0 \n at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.Handle (OmniSharp.Abstractions.Models.V1.FixAll.RunFixAllRequest request) [0x00237] in <7833e4dfb11c41969fc8bb341c494975>:0 \n at OmniSharp.Endpoint.EndpointHandler2[TRequest,TResponse].AggregateResponsesFromLanguageHandlers (OmniSharp.Endpoint.Exports.ExportHandler2[TRequest,TResponse][] handlers, TRequest request) [0x000a9] in <5f96298298f74346ad96eb79547a94e4>:0 \n at OmniSharp.Endpoint.EndpointHandler2[TRequest,TResponse].HandleRequestForLanguage (System.String language, TRequest request, OmniSharp.Protocol.RequestPacket packet) [0x000fb] in <5f96298298f74346ad96eb79547a94e4>:0 \n at OmniSharp.Endpoint.EndpointHandler2[TRequest,TResponse].Process (OmniSharp.Protocol.RequestPacket packet, OmniSharp.Endpoint.LanguageModel model, Newtonsoft.Json.Linq.JToken requestObject) [0x0024b] in <5f96298298f74346ad96eb79547a94e4>:0 \n at OmniSharp.Stdio.Host.HandleRequest (System.String json, Microsoft.Extensions.Logging.ILogger logger) [0x000f3] in <25aad3e40a2c409a9df3868c7895a306>:0 "

Steps to reproduce :

I do not encounter this problem when I fix issues one by one.

OS: MacOS Monterey 12.1 VSCode version : 1.63.2 C# Omnisharp extension version : 1.24.0

dotnet --info _SDK .NET (reflétant tous les fichiers global.json) : Version: 6.0.101 Commit: ef49f6213a

Environnement d'exécution : OS Name: Mac OS X OS Version: 12.1 OS Platform: Darwin RID: osx.12-x64 Base Path: /usr/local/share/dotnet/sdk/6.0.101/

Host (useful for support): Version: 6.0.1 Commit: 3a25a7f1cc

.NET SDKs installed: 3.1.412 [/usr/local/share/dotnet/sdk] 6.0.101 [/usr/local/share/dotnet/sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.18 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.18 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET runtimes or SDKs: https://aka.ms/dotnet-download_

Any help would be really appreciated, thanks :)

jelitter commented 1 year ago

I face a similar issue with the "Fix All" command:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'position')
   at Microsoft.CodeAnalysis.SyntaxNode.FindTokenCore(Int32 position, Boolean findInsideTrivia)
   at Microsoft.CodeAnalysis.SyntaxNode.FindTokenCore(Int32 position, Func`2 stepInto)
   at Microsoft.CodeAnalysis.SyntaxNode.FindTokenCore(Int32 position, Boolean findInsideTrivia)
   at Roslynator.CSharp.CodeFixes.WhitespaceTriviaCodeFixProvider.RegisterCodeFixesAsync(CodeFixContext context)
   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.FixSpecificDiagnosticIdAsync(Document document, String diagnosticId, FixAllScope scope, CancellationToken cancellationToken) in D:\\a\\1\\s\\src\\OmniSharp.Roslyn.CSharp\\Services\\Refactoring\\RunFixAllCodeActionService.cs:line 205
   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.Handle(RunFixAllRequest request) in D:\\a\\1\\s\\src\\OmniSharp.Roslyn.CSharp\\Services\\Refactoring\\RunFixAllCodeActionService.cs:line 110
   at OmniSharp.Endpoint.EndpointHandler`2.AggregateResponsesFromLanguageHandlers(ExportHandler`2[] handlers, TRequest request) in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 190
   at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 233
   at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in D:\\a\\1\\s\\src\\OmniSharp.Host\\Endpoint\\EndpointHandler.cs:line 142
   at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in D:\\a\\1\\s\\src\\OmniSharp.Stdio\\Host.cs:line 258

“error”

> dotnet --info
.NET SDK:
 Version:   7.0.201
 Commit:    68f2d7e7a3

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

Host:
  Version:      7.0.3
  Architecture: x64
  Commit:       0a2bda10e8

.NET SDKs installed:
  5.0.408 [C:\Program Files\dotnet\sdk]
  6.0.406 [C:\Program Files\dotnet\sdk]
  7.0.103 [C:\Program Files\dotnet\sdk]
  7.0.200 [C:\Program Files\dotnet\sdk]
  7.0.201 [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.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.3 [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.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.3 [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.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.3 [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

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download