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

AD0001 Analyzer 'Microsoft.CodeAnalysis.CSharp.RemoveUnnecessarySuppressions.CSharpRemoveUnnecessarySuppressionsDiagnosticAnalyzer' threw an exception of type 'System.InvalidOperationException' #46588

Closed
tmm360 opened this issue Aug 6, 2020 · 3 comments
Assignees
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it IDE-CodeStyle Built-in analyzers, fixes, and refactorings
Milestone

Comments

@tmm360
Copy link

tmm360 commented Aug 6, 2020

With new Visual Studio release is raised a new warning when in project there is GlobalSuppressions.cs with scope on namespaceanddescendants. This is the warning text:

Severity	Code	Description	Project	File	Line	Suppression State
Warning	AD0001	Analyzer 'Microsoft.CodeAnalysis.CSharp.RemoveUnnecessarySuppressions.CSharpRemoveUnnecessarySuppressionsDiagnosticAnalyzer' threw an exception of type 'System.InvalidOperationException' with message 'Unexpected value 'NamespaceAndDescendants' of type 'Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState+TargetScope''.
Exception occurred with following context:
Compilation: ConsoleApp1
SyntaxTree: C:\Users\mirko\Desktop\wow\ConsoleApp1\ConsoleApp1\GlobalSuppressions.cs
SyntaxNode: [assembly: SuppressMessage("Usage" ... [AttributeListSyntax]@[294..476) (7,0)-(7,182)

System.InvalidOperationException: Unexpected value 'NamespaceAndDescendants' of type 'Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState+TargetScope'
   in Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.TargetSymbolResolver.Resolve(Boolean& resolvedWithDocCommentIdFormat)
   in Microsoft.CodeAnalysis.Diagnostics.SuppressMessageAttributeState.HasValidTarget(ImmutableArray`1 namedAttributeArguments, TargetScope targetScope, Boolean& targetHasDocCommentIdFormat, String& targetSymbolString, IOperation& targetValueOperation, ImmutableArray`1& resolvedSymbols)
   in Microsoft.CodeAnalysis.RemoveUnnecessarySuppressions.AbstractRemoveUnnecessarySuppressionsDiagnosticAnalyzer.CompilationAnalyzer.AnalyzeAssemblyOrModuleAttribute(SyntaxNode attributeSyntax, SemanticModel model, Action`1 reportDiagnostic, CancellationToken cancellationToken)
   in Microsoft.CodeAnalysis.CSharp.RemoveUnnecessarySuppressions.CSharpRemoveUnnecessarySuppressionsDiagnosticAnalyzer.<>c__DisplayClass0_0.<RegisterAttributeSyntaxAction>b__0(SyntaxNodeAnalysisContext context)
   in Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__58`1.<ExecuteSyntaxNodeAction>b__58_0(ValueTuple`2 data)
   in Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----

Suppress the following diagnostics to disable this analyzer: IDE0076, IDE0077	ConsoleApp1		1	Active

Version Used:
Microsoft Visual Studio Community 2019 Version 16.7.0
C# Tools 3.7.0-6.20375.2+34202cc2f3e869fd70a26d8237f4552cf9e192cf

Steps to Reproduce:

  1. Create a new .Net Core console application with netcoreapp3.1
  2. Add a GlobalSuppressions.cs file with a sample SuppressMessage with scope on namespaceanddescendants. Example:
using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Usage", "CA2214:Do not call overridable methods in constructors", Justification = "<pending>", Scope = "namespaceanddescendants", Target = "ConsoleApp1")]

Expected Behavior:

As for previous versions, I expect to not receive any warning.

Actual Behavior:

A warning is raised for this code.

@jnm2
Copy link
Contributor

jnm2 commented Aug 8, 2020

@floreseken
Copy link

+1

@mavasani
Copy link
Contributor

Duplicate of #45465, fixed in 16.8 P1

@jinujoseph jinujoseph added help wanted The issue is "up for grabs" - add a comment if you are interested in working on it IDE-CodeStyle Built-in analyzers, fixes, and refactorings labels Aug 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it IDE-CodeStyle Built-in analyzers, fixes, and refactorings
Projects
None yet
Development

No branches or pull requests

5 participants