roslyn: Warning AD0001 Analyzer 'Microsoft.CodeAnalysis.CSharp.RemoveUnusedParametersAndValues.CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer' threw an exception of type 'System.NullReferenceException'
Version Used: VS 2019 Preview 28508.105.d16.0 C# Tools 3.0.0-beta2-19055-10+15504ac30ab7b6f5bfedcdeee0a180915689f66f
Steps to Reproduce: I don’t have a repro yet. The following warnings are showing in my Error List
Severity Code Description Project File Line Suppression State Detail Description
Warning AD0001 Analyzer 'Microsoft.CodeAnalysis.CSharp.RemoveUnusedParametersAndValues.CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. Microsoft.CodeAnalysis.Converter 1 Active Analyzer 'Microsoft.CodeAnalysis.CSharp.RemoveUnusedParametersAndValues.CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer' threw the following exception:
'Exception occurred with following context:
Compilation: Microsoft.CodeAnalysis.Converter
ISymbol: VisitSimpleArgument (Method)
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.CodeAnalysis.FlowAnalysis.SymbolUsageAnalysis.SymbolUsageAnalysis.AnalysisData.OnWriteReferenceFound(ISymbol symbol, IOperation operation, Boolean maybeWritten)
at Microsoft.CodeAnalysis.FlowAnalysis.SymbolUsageAnalysis.SymbolUsageAnalysis.Walker.OnReferenceFound(ISymbol symbol, IOperation operation)
at Microsoft.CodeAnalysis.FlowAnalysis.SymbolUsageAnalysis.SymbolUsageAnalysis.Walker.VisitDeclarationPattern(IDeclarationPatternOperation operation)
at Microsoft.CodeAnalysis.Operations.DeclarationPatternOperation.Accept(OperationVisitor visitor)
at Microsoft.CodeAnalysis.Operations.OperationWalker.Visit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationWalker.VisitArray[T](IEnumerable`1 operations)
at Microsoft.CodeAnalysis.Operations.OperationWalker.DefaultVisit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitPatternCaseClause(IPatternCaseClauseOperation operation)
at Microsoft.CodeAnalysis.Operations.BasePatternCaseClauseOperation.Accept(OperationVisitor visitor)
at Microsoft.CodeAnalysis.Operations.OperationWalker.Visit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationWalker.VisitArray[T](IEnumerable`1 operations)
at Microsoft.CodeAnalysis.Operations.OperationWalker.DefaultVisit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitSwitchCase(ISwitchCaseOperation operation)
at Microsoft.CodeAnalysis.Operations.BaseSwitchCaseOperation.Accept(OperationVisitor visitor)
at Microsoft.CodeAnalysis.Operations.OperationWalker.Visit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationWalker.VisitArray[T](IEnumerable`1 operations)
at Microsoft.CodeAnalysis.Operations.OperationWalker.DefaultVisit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitSwitch(ISwitchOperation operation)
at Microsoft.CodeAnalysis.Operations.BaseSwitchOperation.Accept(OperationVisitor visitor)
at Microsoft.CodeAnalysis.Operations.OperationWalker.Visit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationWalker.VisitArray[T](IEnumerable`1 operations)
at Microsoft.CodeAnalysis.Operations.OperationWalker.DefaultVisit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitBlock(IBlockOperation operation)
at Microsoft.CodeAnalysis.Operations.BaseBlockOperation.Accept(OperationVisitor visitor)
at Microsoft.CodeAnalysis.Operations.OperationWalker.Visit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationWalker.VisitArray[T](IEnumerable`1 operations)
at Microsoft.CodeAnalysis.Operations.OperationWalker.DefaultVisit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitConditional(IConditionalOperation operation)
at Microsoft.CodeAnalysis.Operations.BaseConditionalOperation.Accept(OperationVisitor visitor)
at Microsoft.CodeAnalysis.Operations.OperationWalker.Visit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationWalker.VisitArray[T](IEnumerable`1 operations)
at Microsoft.CodeAnalysis.Operations.OperationWalker.DefaultVisit(IOperation operation)
at Microsoft.CodeAnalysis.Operations.OperationVisitor.VisitBlock(IBlockOperation operation)
at Microsoft.CodeAnalysis.Operations.BaseBlockOperation.Accept(OperationVisitor visitor)
at Microsoft.CodeAnalysis.Operations.OperationWalker.Visit(IOperation operation)
at Microsoft.CodeAnalysis.FlowAnalysis.SymbolUsageAnalysis.SymbolUsageAnalysis.Walker.Visit(IEnumerable`1 operations, AnalysisData analysisData, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.FlowAnalysis.SymbolUsageAnalysis.SymbolUsageAnalysis.Walker.AnalyzeOperationsAndUpdateData(IEnumerable`1 operations, AnalysisData analysisData, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.FlowAnalysis.SymbolUsageAnalysis.SymbolUsageAnalysis.Run(IOperation rootOperation, ISymbol owningSymbol, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.RemoveUnusedParametersAndValues.AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.AnalyzeUnusedValueAssignments(OperationBlockAnalysisContext context, Boolean isComputingUnusedParams, PooledHashSet`1 symbolUsageResultsBuilder, Boolean& hasBlockWithAllUsedSymbolWrites)
at Microsoft.CodeAnalysis.RemoveUnusedParametersAndValues.AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.AnalyzeOperationBlockEnd(OperationBlockAnalysisContext context)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__55`2.<ExecuteBlockActions>b__55_1(ValueTuple`2 data)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
'.
Expected Behavior:
No AD0001 warnings
Actual Behavior:
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (11 by maintainers)
@mwpowellhtx The AD0001 message you pasted points to an exception in
CSharpDiagnosticAnalyzerApiUsageAnalyzer
, while this issue is about AD0001 inCSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer
, the latter was first added in VS2019.You should be able to resolve the AD0001 in
CSharpDiagnosticAnalyzerApiUsageAnalyzer
by applying the suggestion from https://github.com/dotnet/roslyn-analyzers/issues/2961#issuecomment-545438365@jnm2 The feature that required a breaking change to semantics of
IDeclarationPatternOperation.DeclaredSymbol
was checked in preview2, hence it only repros on preview2. You have few choices here: