Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArgumentException: Argument cannot be empty. (Parameter 'analyzers') #6057

Closed
Tracked by #5951
mavasani opened this issue Aug 7, 2023 · 0 comments · Fixed by dotnet/roslyn#69419
Closed
Tracked by #5951
Assignees

Comments

@mavasani
Copy link
Contributor

mavasani commented Aug 7, 2023

I am intermittently seeing the below exception in C# extension when changing background analysis scope option for compiler and analyzer diagnostics:

[Error - 11:54:21 AM] [LanguageServerHost]System.ArgumentException: Argument cannot be empty. (Parameter 'analyzers')
   at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.VerifyAnalyzersArgumentForStaticApis(ImmutableArray`1 analyzers, Boolean allowDefaultOrEmpty) in /_/src/Compilers/Core/Portable/DiagnosticAnalyzer/CompilationWithAnalyzers.cs:line 136
   at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.VerifyExistingAnalyzersArgument(ImmutableArray`1 analyzers) in /_/src/Compilers/Core/Portable/DiagnosticAnalyzer/CompilationWithAnalyzers.cs:line 171
   at Microsoft.CodeAnalysis.Diagnostics.CompilationWithAnalyzers.GetAnalysisResultAsync(SyntaxTree tree, Nullable`1 filterSpan, ImmutableArray`1 analyzers, CancellationToken cancellationToken) in /_/src/Compilers/Core/Portable/DiagnosticAnalyzer/CompilationWithAnalyzers.cs:line 507
   at Microsoft.CodeAnalysis.Diagnostics.Extensions.GetAnalysisResultAsync(CompilationWithAnalyzers compilationWithAnalyzers, DocumentAnalysisScope documentAnalysisScope, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/Diagnostics/Extensions.cs:line 349
   at Microsoft.CodeAnalysis.Diagnostics.Extensions.GetAnalysisResultAsync(CompilationWithAnalyzers compilationWithAnalyzers, DocumentAnalysisScope documentAnalysisScope, Project project, DiagnosticAnalyzerInfoCache analyzerInfoCache, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/Diagnostics/Extensions.cs:line 325
   at Microsoft.CodeAnalysis.Diagnostics.InProcOrRemoteHostAnalyzerRunner.AnalyzeInProcAsync(DocumentAnalysisScope documentAnalysisScope, Project project, CompilationWithAnalyzers compilationWithAnalyzers, RemoteHostClient client, Boolean logPerformanceInfo, Boolean getTelemetryInfo, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.InProcOrRemoteHostAnalyzerRunner.cs:line 100
   at Microsoft.CodeAnalysis.Diagnostics.InProcOrRemoteHostAnalyzerRunner.<>c__DisplayClass7_0.<<AnalyzeAsync>g__AnalyzeCoreAsync|0>d.MoveNext() in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.InProcOrRemoteHostAnalyzerRunner.cs:line 84
--- End of stack trace from previous location ---
   at Microsoft.CodeAnalysis.Diagnostics.InProcOrRemoteHostAnalyzerRunner.AnalyzeAsync(DocumentAnalysisScope documentAnalysisScope, Project project, CompilationWithAnalyzers compilationWithAnalyzers, Boolean isExplicit, Boolean forceExecuteAllAnalyzers, Boolean logPerformanceInfo, Boolean getTelemetryInfo, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.InProcOrRemoteHostAnalyzerRunner.cs:line 69
   at Microsoft.CodeAnalysis.Diagnostics.DocumentAnalysisExecutor.GetAnalysisResultAsync(DocumentAnalysisScope analysisScope, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor.cs:line 188
   at Microsoft.CodeAnalysis.Diagnostics.DocumentAnalysisExecutor.GetSyntaxDiagnosticsAsync(DiagnosticAnalyzer analyzer, Boolean isCompilerAnalyzer, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor.cs:line 242
   at Microsoft.CodeAnalysis.Diagnostics.DocumentAnalysisExecutor.ComputeDiagnosticsAsync(DiagnosticAnalyzer analyzer, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/DocumentAnalysisExecutor.cs:line 153
   at Microsoft.CodeAnalysis.Diagnostics.EngineV2.DiagnosticIncrementalAnalyzer.LatestDiagnosticsForSpanGetter.ComputeDocumentDiagnosticsForAnalyzerCoreAsync(DiagnosticAnalyzer analyzer, DocumentAnalysisExecutor executor, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs:line 576
   at Microsoft.CodeAnalysis.Diagnostics.EngineV2.DiagnosticIncrementalAnalyzer.LatestDiagnosticsForSpanGetter.ComputeDocumentDiagnosticsCoreAsync(DocumentAnalysisExecutor executor, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs:line 556
   at Microsoft.CodeAnalysis.Diagnostics.EngineV2.DiagnosticIncrementalAnalyzer.LatestDiagnosticsForSpanGetter.ComputeDocumentDiagnosticsAsync(ImmutableArray`1 analyzersWithState, AnalysisKind kind, Nullable`1 span, ArrayBuilder`1 builder, Boolean incrementalAnalysis, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs:line 547
   at Microsoft.CodeAnalysis.Diagnostics.EngineV2.DiagnosticIncrementalAnalyzer.LatestDiagnosticsForSpanGetter.TryGetAsync(ArrayBuilder`1 list, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs:line 275
   at Microsoft.CodeAnalysis.Diagnostics.EngineV2.DiagnosticIncrementalAnalyzer.TryAppendDiagnosticsForSpanAsync(TextDocument document, Nullable`1 range, ArrayBuilder`1 result, Func`2 shouldIncludeDiagnostic, Boolean includeSuppressedDiagnostics, Boolean includeCompilerDiagnostics, ICodeActionRequestPriorityProvider priorityProvider, Boolean blockForData, Func`2 addOperationScope, DiagnosticKind diagnosticKinds, Boolean isExplicit, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs:line 34
   at Microsoft.CodeAnalysis.Diagnostics.EngineV2.DiagnosticIncrementalAnalyzer.GetDiagnosticsForSpanAsync(TextDocument document, Nullable`1 range, Func`2 shouldIncludeDiagnostic, Boolean includeSuppressedDiagnostics, Boolean includeCompilerDiagnostics, ICodeActionRequestPriorityProvider priorityProvider, Boolean blockForData, Func`2 addOperationScope, DiagnosticKind diagnosticKinds, Boolean isExplicit, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer_GetDiagnosticsForSpan.cs:line 51
   at Microsoft.CodeAnalysis.CodeFixes.CodeFixService.StreamFixesAsync(TextDocument document, TextSpan range, ICodeActionRequestPriorityProvider priorityProvider, CodeActionOptionsProvider fallbackOptions, Func`2 addOperationScope, CancellationToken cancellationToken)+MoveNext() in /_/src/Features/LanguageServer/Protocol/Features/CodeFixes/CodeFixService.cs:line 194
   at Microsoft.CodeAnalysis.CodeFixes.CodeFixService.StreamFixesAsync(TextDocument document, TextSpan range, ICodeActionRequestPriorityProvider priorityProvider, CodeActionOptionsProvider fallbackOptions, Func`2 addOperationScope, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Microsoft.CodeAnalysis.Shared.Extensions.IAsyncEnumerableExtensions.ToImmutableArrayAsync[T](IAsyncEnumerable`1 values, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/Shared/Extensions/IAsyncEnumerableExtensions.cs:line 32
   at Microsoft.CodeAnalysis.Shared.Extensions.IAsyncEnumerableExtensions.ToImmutableArrayAsync[T](IAsyncEnumerable`1 values, CancellationToken cancellationToken) in /_/src/Workspaces/Core/Portable/Shared/Extensions/IAsyncEnumerableExtensions.cs:line 32
   at Microsoft.CodeAnalysis.UnifiedSuggestions.UnifiedSuggestedActionsSource.GetFilterAndOrderCodeFixesAsync(Workspace workspace, ICodeFixService codeFixService, TextDocument document, TextSpan selection, ICodeActionRequestPriorityProvider priorityProvider, CodeActionOptionsProvider fallbackOptions, Func`2 addOperationScope, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Features/UnifiedSuggestions/UnifiedSuggestedActionsSource.cs:line 48
   at Microsoft.CodeAnalysis.LanguageServer.Handler.CodeActions.CodeActionHelpers.GetActionSetsAsync(Document document, CodeActionOptionsProvider fallbackOptions, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, Range selection, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionHelpers.cs:line 319
   at Microsoft.CodeAnalysis.LanguageServer.Handler.CodeActions.CodeActionHelpers.GetVSCodeActionsAsync(CodeActionParams request, Document document, CodeActionOptionsProvider fallbackOptions, ICodeFixService codeFixService, ICodeRefactoringService codeRefactoringService, Boolean hasVsLspCapability, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionHelpers.cs:line 40
   at Microsoft.CodeAnalysis.LanguageServer.Handler.CodeActionsHandler.HandleRequestAsync(CodeActionParams request, RequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Protocol/Handler/CodeActions/CodeActionsHandler.cs:line 61
   at Microsoft.CommonLanguageServerProtocol.Framework.QueueItem`3.StartRequestAsync(TRequestContext context, CancellationToken cancellationToken) in /_/src/Features/LanguageServer/Microsoft.CommonLanguageServerProtocol.Framework/QueueItem.cs:line 176
[Error - 11:54:21 AM] Request textDocument/codeAction failed.
  Message: Argument cannot be empty. (Parameter 'analyzers')
  Code: -32000 

I believe there seems to be a missing check for empty trimmed down analyzers based on these options.

@mavasani mavasani self-assigned this Aug 7, 2023
mavasani added a commit to mavasani/roslyn that referenced this issue Aug 7, 2023
…alyzers to be analyzed

Fixes dotnet/vscode-csharp#6057

We were not accounting for the fact that changing the background analysis scope option can increase the set of analyzers to analyze (when option value is changed from None to OpenFiles or FullSolution). Hence we ended up using a cached CompilationWithAnalyzers instance which only had compiler analyzer instance, causing the given ArgumentException.
mavasani added a commit to mavasani/roslyn that referenced this issue Aug 7, 2023
…alyzers to be analyzed

Fixes dotnet/vscode-csharp#6057

We were not accounting for the fact that changing the background analysis scope option can increase the set of analyzers to analyze (when option value is changed from None to OpenFiles or FullSolution). Hence we ended up using a cached CompilationWithAnalyzers instance which only had compiler analyzer instance, causing the given ArgumentException.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant