vscode-csharp icon indicating copy to clipboard operation
vscode-csharp copied to clipboard

Fix all fails fixing style option Add this or me.

Open KyleC69 opened this issue 4 years ago • 4 comments

Issue Type: Bug

Error is consistent when fixing Style error 009 Add this or me Using command Fix all issues within document or within project

Extension version: 1.23.16 VS Code version: Code 1.61.0 (ee8c7def80afc00dd6e593ef12f37756d8f504ea, 2021-10-07T18:11:02.929Z) OS version: Linux x64 5.11.0-37-generic Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i5 CPU M 460 @ 2.53GHz (4 x 1586)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
opengl: enabled_on
rasterization: disabled_software
skia_renderer: enabled_on
video_decode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
Load (avg) 1, 1, 1
Memory (System) 3.64GB (0.56GB free)
Process Argv --unity-launch --log information
Screen Reader no
VM 0%
DESKTOP_SESSION ubuntu
XDG_CURRENT_DESKTOP Unity
XDG_SESSION_DESKTOP ubuntu
XDG_SESSION_TYPE x11
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
pythonvspyt602:30300191
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
pythonvspyt639:30300192
pythontb:30283811
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
pythondataviewer:30285071
pythonvsuse255:30340121
vscod805:30301674
pythonvspyt200:30340761
binariesv615:30325510
vsccppwtct:30378365
pythonvssor306:30344512
bridge0708:30335490
pygetstartedt2:30371810
dockerwalkthru:30377721
bridge0723:30353136
pythonrunftest32:30373476
pythonf5test824:30373475
javagetstartedt:30364666
pythonvspyt187:30373474
vsqsis200cf:30381675
vsaa593cf:30376535
vssld246:30379911

We have written the needed data into your clipboard because it was too large to send. Please paste.

KyleC69 avatar Oct 13 '21 14:10 KyleC69

Additional info during attempt to fix all: [info]: OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService Fixing IDE0009. [warn]: OmniSharp.Stdio.Host ************ Request ************ { "Type": "request", "Seq": 929, "Command": "/runfixall", "Arguments": { "FileName": "/home/savaho/Documents/codex/Scavenger/Extensions/AsyncSemaphore.cs", "Scope": "Project", "FixAllFilter": [ { "Id": "IDE0009", "Message": " Add 'this' or 'Me' qualification." } ], "WantsAllCodeActionOperations": true, "WantsTextChanges": true, "ApplyChanges": false } } [fail]: OmniSharp.Stdio.Host ************ Response (10197.0283ms) ************ { "Request_seq": 929, "Command": "/runfixall", "Running": true, "Success": false, "Message": ""System.Threading.Tasks.TaskCanceledException: A task was canceled.\n at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.GetFixedDocumentsAsync (Microsoft.CodeAnalysis.CodeFixes.FixAllContext fixAllContext, Microsoft.CodeAnalysis.Shared.Utilities.IProgressTracker progressTracker, System.Collections.Immutable.ImmutableArray1[T] diagnostics) [0x001f5] in <9dccb33d013140559336b134d73ba782>:0 \\n at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.FixSingleContextAsync (Microsoft.CodeAnalysis.Solution currentSolution, Microsoft.CodeAnalysis.CodeFixes.FixAllContext fixAllContext, Microsoft.CodeAnalysis.Shared.Utilities.IProgressTracker progressTracker) [0x00102] in <9dccb33d013140559336b134d73ba782>:0 \\n at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.FixAllContextsAsync (Microsoft.CodeAnalysis.CodeFixes.FixAllContext originalFixAllContext, System.Collections.Immutable.ImmutableArray1[T] fixAllContexts) [0x0010f] in <9dccb33d013140559336b134d73ba782>:0 \n at Microsoft.CodeAnalysis.CodeFixes.DefaultFixAllProviderHelpers.GetFixAsync (System.String title, Microsoft.CodeAnalysis.CodeFixes.FixAllContext fixAllContext, System.Func3[T1,T2,TResult] fixAllContextsAsync) [0x00153] in <9dccb33d013140559336b134d73ba782>:0 \\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) [0x0038b] in <0be23d9d0cfd4fc2bf929dbc1b294ce9>:0 \\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.Handle (OmniSharp.Abstractions.Models.V1.FixAll.RunFixAllRequest request) [0x00306] in <0be23d9d0cfd4fc2bf929dbc1b294ce9>:0 \\n at OmniSharp.Endpoint.EndpointHandler2[TRequest,TResponse].AggregateResponsesFromLanguageHandlers (OmniSharp.Endpoint.Exports.ExportHandler2[TRequest,TResponse][] handlers, TRequest request) [0x000a9] in <78785a359ccc4badaf9737c7917fb137>:0 \\n at OmniSharp.Endpoint.EndpointHandler2[TRequest,TResponse].HandleRequestForLanguage (System.String language, TRequest request, OmniSharp.Protocol.RequestPacket packet) [0x000fb] in <78785a359ccc4badaf9737c7917fb137>:0 \n at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].Process (OmniSharp.Protocol.RequestPacket packet, OmniSharp.Endpoint.LanguageModel model, Newtonsoft.Json.Linq.JToken requestObject) [0x0024b] in <78785a359ccc4badaf9737c7917fb137>:0 \n at OmniSharp.Stdio.Host.HandleRequest (System.String json, Microsoft.Extensions.Logging.ILogger logger) [0x000f3] in <7914476593d54cafbaff70d2845dcd09>:0 "", "Body": null, "Seq": 814, "Type": "response" }

KyleC69 avatar Oct 13 '21 15:10 KyleC69

Same issue with different fix after latest updates .Net/Vscode

omnisharp log: ************ Request ************ { "Type": "request", "Seq": 49, "Command": "/runfixall", "Arguments": { "FileName": "/home/savaho/Documents/codex/Scavenger/Modules/DataController.cs", "Scope": "Document", "FixAllFilter": [ { "Id": "IDE0090", "Message": " 'new' expression can be simplified" } ], "WantsAllCodeActionOperations": true, "WantsTextChanges": true, "ApplyChanges": false } } [fail]: OmniSharp.Stdio.Host ************ Response (714.5037ms) ************ { "Request_seq": 49, "Command": "/runfixall", "Running": true, "Success": false, "Message": ""System.InvalidOperationException: GetCurrentNode returned null with the following node: new LinkDBContext() - line 321\n at Roslyn.Utilities.Contract.Fail (System.String message, System.Int32 lineNumber) [0x00011] in <9dccb33d013140559336b134d73ba782>:0 \n at Microsoft.CodeAnalysis.Editing.SyntaxEditor+ReplaceChange.Apply (Microsoft.CodeAnalysis.SyntaxNode root, Microsoft.CodeAnalysis.Editing.SyntaxGenerator generator) [0x00020] in <9dccb33d013140559336b134d73ba782>:0 \n at Microsoft.CodeAnalysis.Editing.SyntaxEditor.GetChangedRoot () [0x00063] in <9dccb33d013140559336b134d73ba782>:0 \n at Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync (Microsoft.CodeAnalysis.Document document, System.Func2[T,TResult] editAsync, System.Threading.CancellationToken cancellationToken) [0x0011a] in <9dccb33d013140559336b134d73ba782>:0 \\n at Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.<GetFixAllProvider>b__2_0 (Microsoft.CodeAnalysis.CodeFixes.FixAllContext fixAllContext, Microsoft.CodeAnalysis.Document document, System.Collections.Immutable.ImmutableArray1[T] diagnostics) [0x001c8] in <9dccb33d013140559336b134d73ba782>:0 \n at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider+<>c__DisplayClass8_1.<GetFixedDocumentsAsync>b__2 () [0x000a2] in <9dccb33d013140559336b134d73ba782>:0 \n at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.GetFixedDocumentsAsync (Microsoft.CodeAnalysis.CodeFixes.FixAllContext fixAllContext, Microsoft.CodeAnalysis.Shared.Utilities.IProgressTracker progressTracker, System.Collections.Immutable.ImmutableArray1[T] diagnostics) [0x001f5] in <9dccb33d013140559336b134d73ba782>:0 \\n at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.FixSingleContextAsync (Microsoft.CodeAnalysis.Solution currentSolution, Microsoft.CodeAnalysis.CodeFixes.FixAllContext fixAllContext, Microsoft.CodeAnalysis.Shared.Utilities.IProgressTracker progressTracker) [0x00102] in <9dccb33d013140559336b134d73ba782>:0 \\n at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.FixAllContextsAsync (Microsoft.CodeAnalysis.CodeFixes.FixAllContext originalFixAllContext, System.Collections.Immutable.ImmutableArray1[T] fixAllContexts) [0x0010f] in <9dccb33d013140559336b134d73ba782>:0 \n at Microsoft.CodeAnalysis.CodeFixes.DefaultFixAllProviderHelpers.GetFixAsync (System.String title, Microsoft.CodeAnalysis.CodeFixes.FixAllContext fixAllContext, System.Func3[T1,T2,TResult] fixAllContextsAsync) [0x000da] in <9dccb33d013140559336b134d73ba782>:0 \\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) [0x0038b] in <0be23d9d0cfd4fc2bf929dbc1b294ce9>:0 \\n at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.Handle (OmniSharp.Abstractions.Models.V1.FixAll.RunFixAllRequest request) [0x00306] in <0be23d9d0cfd4fc2bf929dbc1b294ce9>:0 \\n at OmniSharp.Endpoint.EndpointHandler2[TRequest,TResponse].AggregateResponsesFromLanguageHandlers (OmniSharp.Endpoint.Exports.ExportHandler2[TRequest,TResponse][] handlers, TRequest request) [0x000a9] in <78785a359ccc4badaf9737c7917fb137>:0 \\n at OmniSharp.Endpoint.EndpointHandler2[TRequest,TResponse].HandleRequestForLanguage (System.String language, TRequest request, OmniSharp.Protocol.RequestPacket packet) [0x000fb] in <78785a359ccc4badaf9737c7917fb137>:0 \n at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].Process (OmniSharp.Protocol.RequestPacket packet, OmniSharp.Endpoint.LanguageModel model, Newtonsoft.Json.Linq.JToken requestObject) [0x0024b] in <78785a359ccc4badaf9737c7917fb137>:0 \n at OmniSharp.Stdio.Host.HandleRequest (System.String json, Microsoft.Extensions.Logging.ILogger logger) [0x000f3] in <7914476593d54cafbaff70d2845dcd09>:0 "", "Body": null, "Seq": 156, "Type": "response" }

KyleC69 avatar Oct 15 '21 12:10 KyleC69

This could be an issue in Roslyn, we will need to investigate this. Do you have a consistent repro that you could share, please?

nohwnd avatar Oct 19 '21 16:10 nohwnd

This is the log I'm seeing:

[warn]: OmniSharp.Stdio.Host
        ************ Request ************
{
  "Type": "request",
  "Seq": 406,
  "Command": "/runfixall",
  "Arguments": {
    "FileName": "<PATH_TO_A_FILE>.cs",
    "Scope": "Document",
    "WantsAllCodeActionOperations": true,
    "WantsTextChanges": true,
    "ApplyChanges": false
  }
}
[fail]: OmniSharp.Stdio.Host
        ************  Response (4185.7672ms) ************ 
{
  "Request_seq": 406,
  "Command": "/runfixall",
  "Running": true,
  "Success": false,
  "Message": "\"System.InvalidOperationException: GetCurrentNode returned null with the following node: var - line 280\\n   at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber)\\n   at Microsoft.CodeAnalysis.Editing.SyntaxEditor.GetChangedRoot()\\n   at Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync(Document document, Func`2 editAsync, CancellationToken cancellationToken)\\n   at Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.<GetFixAllProvider>b__3_0(FixAllContext fixAllContext, Document document, ImmutableArray`1 diagnostics)\\n   at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.<>c__DisplayClass10_1.<<GetFixedDocumentsAsync>b__0>d.MoveNext()\\n--- End of stack trace from previous location ---\\n   at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.GetFixedDocumentsAsync(FixAllContext fixAllContext, IProgressTracker progressTracker, ImmutableDictionary`2 diagnostics)\\n   at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.DetermineDiagnosticsAndGetFixedDocumentsAsync(FixAllContext fixAllContext, IProgressTracker progressTracker)\\n   at Microsoft.CodeAnalysis.CodeFixesAndRefactorings.DocumentBasedFixAllProviderHelpers.FixSingleContextAsync[TFixAllContext](Solution currentSolution, TFixAllContext fixAllContext, IProgressTracker progressTracker, Func`3 getFixedDocumentsAsync)\\n   at Microsoft.CodeAnalysis.CodeFixesAndRefactorings.DocumentBasedFixAllProviderHelpers.FixAllContextsAsync[TFixAllContext](TFixAllContext originalFixAllContext, ImmutableArray`1 fixAllContexts, IProgressTracker progressTracker, String progressTrackerDescription, Func`3 getFixedDocumentsAsync)\\n   at Microsoft.CodeAnalysis.CodeFixesAndRefactorings.DefaultFixAllProviderHelpers.GetFixAsync[TFixAllContext](String title, TFixAllContext fixAllContext, Func`3 fixAllContextsAsync)\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.FixSpecificDiagnosticIdAsync(Document document, String diagnosticId, FixAllScope scope, CancellationToken cancellationToken) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 183\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.Handle(RunFixAllRequest request) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 80\\n   at OmniSharp.Endpoint.EndpointHandler`2.AggregateResponsesFromLanguageHandlers(ExportHandler`2[] handlers, TRequest request) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 191\\n   at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 234\\n   at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 143\\n   at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in /Users/runner/work/1/s/src/OmniSharp.Stdio/Host.cs:line 258\"",
  "Body": null,
  "Seq": 1383,
  "Type": "response"
}

The message after unescaping new lines:

System.InvalidOperationException: GetCurrentNode returned null with the following node: var - line 280
   at Roslyn.Utilities.Contract.Fail(String message, Int32 lineNumber)
   at Microsoft.CodeAnalysis.Editing.SyntaxEditor.GetChangedRoot()
   at Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.FixAllWithEditorAsync(Document document, Func`2 editAsync, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.CodeFixes.SyntaxEditorBasedCodeFixProvider.<GetFixAllProvider>b__3_0(FixAllContext fixAllContext, Document document, ImmutableArray`1 diagnostics)
   at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.<>c__DisplayClass10_1.<<GetFixedDocumentsAsync>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.GetFixedDocumentsAsync(FixAllContext fixAllContext, IProgressTracker progressTracker, ImmutableDictionary`2 diagnostics)
   at Microsoft.CodeAnalysis.CodeFixes.DocumentBasedFixAllProvider.DetermineDiagnosticsAndGetFixedDocumentsAsync(FixAllContext fixAllContext, IProgressTracker progressTracker)
   at Microsoft.CodeAnalysis.CodeFixesAndRefactorings.DocumentBasedFixAllProviderHelpers.FixSingleContextAsync[TFixAllContext](Solution currentSolution, TFixAllContext fixAllContext, IProgressTracker progressTracker, Func`3 getFixedDocumentsAsync)
   at Microsoft.CodeAnalysis.CodeFixesAndRefactorings.DocumentBasedFixAllProviderHelpers.FixAllContextsAsync[TFixAllContext](TFixAllContext originalFixAllContext, ImmutableArray`1 fixAllContexts, IProgressTracker progressTracker, String progressTrackerDescription, Func`3 getFixedDocumentsAsync)
   at Microsoft.CodeAnalysis.CodeFixesAndRefactorings.DefaultFixAllProviderHelpers.GetFixAsync[TFixAllContext](String title, TFixAllContext fixAllContext, Func`3 fixAllContextsAsync)
   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.FixSpecificDiagnosticIdAsync(Document document, String diagnosticId, FixAllScope scope, CancellationToken cancellationToken) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 183
   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.Handle(RunFixAllRequest request) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 80
   at OmniSharp.Endpoint.EndpointHandler`2.AggregateResponsesFromLanguageHandlers(ExportHandler`2[] handlers, TRequest request) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 191
   at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 234
   at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 143
   at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in /Users/runner/work/1/s/src/OmniSharp.Stdio/Host.cs:line 258

I'm unable to get a repro but it seems related to using statements.

In another file's case I worked around it by making some type imports be in the form ParentNamespace.MyClass instead of adding using ParentNamespace;. In this file's case I kept commenting everything until I noticed I had a reference of IMapper from Automapper. But trying AutoMapper.IMapper did not work this time (AutoMapper has been in the project for ages and build is successful, so restore is complete).

"Fix all" is also broken in my case. I think it tries to parse files until it gets to the files it doesn't like and break at this kind of errors.

Meligy avatar Jun 26 '22 23:06 Meligy

It just happened to me again, showing like this:

{
  "Request_seq": 341,
  "Command": "/runfixall",
  "Running": true,
  "Success": false,
  "Message": "\"System.NullReferenceException: Object reference not set to an instance of an object.\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.FixSpecificDiagnosticIdAsync(Document document, String diagnosticId, FixAllScope scope, CancellationToken cancellationToken) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 170\\n   at OmniSharp.Roslyn.CSharp.Services.Refactoring.RunFixAllCodeActionService.Handle(RunFixAllRequest request) in /Users/runner/work/1/s/src/OmniSharp.Roslyn.CSharp/Services/Refactoring/RunFixAllCodeActionService.cs:line 80\\n   at OmniSharp.Endpoint.EndpointHandler`2.AggregateResponsesFromLanguageHandlers(ExportHandler`2[] handlers, TRequest request) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 190\\n   at OmniSharp.Endpoint.EndpointHandler`2.HandleRequestForLanguage(String language, TRequest request, RequestPacket packet) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 233\\n   at OmniSharp.Endpoint.EndpointHandler`2.Process(RequestPacket packet, LanguageModel model, JToken requestObject) in /Users/runner/work/1/s/src/OmniSharp.Host/Endpoint/EndpointHandler.cs:line 142\\n   at OmniSharp.Stdio.Host.HandleRequest(String json, ILogger logger) in /Users/runner/work/1/s/src/OmniSharp.Stdio/Host.cs:line 258\"",
  "Body": null,
  "Seq": 1189,
  "Type": "response"
}

I also saw other messages, not sure if related:

Received response for /v2/getcodeactions but could not find request.
[fail]: OmniSharp.Stdio.Host

And sometimes, probably not relevant:

Received response for /findusages but could not find request.

Meligy avatar Feb 21 '23 02:02 Meligy

+1

philcarbone avatar Apr 11 '23 03:04 philcarbone