Error AD0001 Analyzer 'SonarAnalyzer.Rules.CSharp.SymbolicExecutionRunner' threw an exception

  • SonarQube 9.5
  • SonarLint 6.6.0
  • Visual Studio 17.2.2

The Errors and Warnings window for my AspNetCore 3.1 app is showing the analyzer crashed:

Severity    Code    Description Project Path    File    Line    Suppression State
Error   AD0001  Analyzer 'SonarAnalyzer.Rules.CSharp.SymbolicExecutionRunner' threw an exception of type 'SonarAnalyzer.SymbolicExecution.SymbolicExecutionException' with message 'Error processing method: MyMethod1 ## Method file: C:\PATHTOMYMETHODFILE.cs ## Method line: 136,8 ## Inner exception: System.ArgumentNullException: Value cannot be null. ## Parameter name: key ##    at System.Collections.Immutable.Requires.FailArgumentNullException(String parameterName) ##    at System.Collections.Immutable.ImmutableDictionary`2.SetItem(TKey key, TValue value) ##    at SonarAnalyzer.SymbolicExecution.Sonar.ProgramState.StoreSymbolicValue(ISymbol symbol, SymbolicValue newSymbolicValue) ##    at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitParenthesizedVariableDesignationSyntax(ParenthesizedVariableDesignationSyntaxWrapper designation, ProgramState programState) ##    at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitDeclarationExpression(DeclarationExpressionSyntaxWrapper wrapper, ProgramState programState) ##    at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitInstruction(ExplodedGraphNode node) ##    at SonarAnalyzer.SymbolicExecution.Sonar.AbstractExplodedGraph.Walk() ##    at SonarAnalyzer.Rules.CSharp.SymbolicExecutionRunner.AnalyzeSonar(SyntaxNodeAnalysisContext context, Boolean isTestProject, Boolean isScannerRun, SyntaxNode body, ISymbol symbol)'.
Exception occurred with following context:
Compilation: MyCompany.MyService.API
SyntaxTree: C:\dev\MYSolution\MyService\MyService.API\Controllers\MyController.cs
SyntaxNode: private async Task<PortfolioPositionsPatchResult ... [MethodDeclarationSyntax]@[7228..10644) (135,8)-(196,9)

SonarAnalyzer.SymbolicExecution.SymbolicExecutionException: Error processing method: MyMethod1 ## Method file: C:\PATHTOMYMETHODFILE.cs ## Method line: 136,8 ## Inner exception: System.ArgumentNullException: Value cannot be null. ## Parameter name: key ##    at System.Collections.Immutable.Requires.FailArgumentNullException(String parameterName) ##    at System.Collections.Immutable.ImmutableDictionary`2.SetItem(TKey key, TValue value) ##    at SonarAnalyzer.SymbolicExecution.Sonar.ProgramState.StoreSymbolicValue(ISymbol symbol, SymbolicValue newSymbolicValue) ##    at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitParenthesizedVariableDesignationSyntax(ParenthesizedVariableDesignationSyntaxWrapper designation, ProgramState programState) ##    at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitDeclarationExpression(DeclarationExpressionSyntaxWrapper wrapper, ProgramState programState) ##    at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitInstruction(ExplodedGraphNode node) ##    at SonarAnalyzer.SymbolicExecution.Sonar.AbstractExplodedGraph.Walk() ##    at SonarAnalyzer.Rules.CSharp.SymbolicExecutionRunner.AnalyzeSonar(SyntaxNodeAnalysisContext context, Boolean isTestProject, Boolean isScannerRun, SyntaxNode body, ISymbol symbol) ---> System.ArgumentNullException: Value cannot be null.
Parameter name: key
   at System.Collections.Immutable.Requires.FailArgumentNullException(String parameterName)
   at System.Collections.Immutable.ImmutableDictionary`2.SetItem(TKey key, TValue value)
   at SonarAnalyzer.SymbolicExecution.Sonar.ProgramState.StoreSymbolicValue(ISymbol symbol, SymbolicValue newSymbolicValue)
   at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitParenthesizedVariableDesignationSyntax(ParenthesizedVariableDesignationSyntaxWrapper designation, ProgramState programState)
   at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitDeclarationExpression(DeclarationExpressionSyntaxWrapper wrapper, ProgramState programState)
   at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitInstruction(ExplodedGraphNode node)
   at SonarAnalyzer.SymbolicExecution.Sonar.AbstractExplodedGraph.Walk()
   at SonarAnalyzer.Rules.CSharp.SymbolicExecutionRunner.AnalyzeSonar(SyntaxNodeAnalysisContext context, Boolean isTestProject, Boolean isScannerRun, SyntaxNode body, ISymbol symbol)
   --- End of inner exception stack trace ---
   at SonarAnalyzer.Rules.CSharp.SymbolicExecutionRunner.AnalyzeSonar(SyntaxNodeAnalysisContext context, Boolean isTestProject, Boolean isScannerRun, SyntaxNode body, ISymbol symbol)
   at SonarAnalyzer.Rules.SymbolicExecutionRunnerBase.Analyze(SonarAnalysisContext sonarContext, SyntaxNodeAnalysisContext nodeContext, SyntaxNode body, ISymbol symbol)
   at SonarAnalyzer.Rules.SymbolicExecutionRunnerBase.Analyze[TNode](SonarAnalysisContext analysisContext, SyntaxNodeAnalysisContext context, Func`2 getBody)
   at SonarAnalyzer.Rules.CSharp.SymbolicExecutionRunner.<>c__DisplayClass5_0.<Initialize>b__0(SyntaxNodeAnalysisContext c)
   at SonarAnalyzer.Helpers.DiagnosticAnalyzerContextHelper.<>c__DisplayClass1_0`1.<RegisterSyntaxNodeActionInNonGenerated>b__0(SyntaxNodeAnalysisContext c)
   at SonarAnalyzer.Helpers.SonarAnalysisContext.<>c__DisplayClass47_0`1.<RegisterContextAction>b__0(TContext c)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.<>c__62`1.<ExecuteSyntaxNodeAction>b__62_0(ValueTuple`2 data)
   at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info)
-----
System.ArgumentNullException: Value cannot be null.
Parameter name: key
   at System.Collections.Immutable.Requires.FailArgumentNullException(String parameterName)
   at System.Collections.Immutable.ImmutableDictionary`2.SetItem(TKey key, TValue value)
   at SonarAnalyzer.SymbolicExecution.Sonar.ProgramState.StoreSymbolicValue(ISymbol symbol, SymbolicValue newSymbolicValue)
   at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitParenthesizedVariableDesignationSyntax(ParenthesizedVariableDesignationSyntaxWrapper designation, ProgramState programState)
   at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitDeclarationExpression(DeclarationExpressionSyntaxWrapper wrapper, ProgramState programState)
   at SonarAnalyzer.SymbolicExecution.Sonar.SonarExplodedGraph.VisitInstruction(ExplodedGraphNode node)
   at SonarAnalyzer.SymbolicExecution.Sonar.AbstractExplodedGraph.Walk()
   at SonarAnalyzer.Rules.CSharp.SymbolicExecutionRunner.AnalyzeSonar(SyntaxNodeAnalysisContext context, Boolean isTestProject, Boolean isScannerRun, SyntaxNode body, ISymbol symbol)
-----

Suppress the following diagnostics to disable this analyzer: S1944, S2053, S2222, S2259, S2583, S2589, S3329, S3655, S3900, S3966, S4158, S5773 MyService.API         1   Active

This is in a controller that has approximately

[HttpPatch]
[Route("{someDate:route-date}")]
public async Task<IActionResult> MyAction(DateTime someDate, [Required [FromBody] SomeModel body)
{
    return someBool ? await Method1(someDate, body) : await Method2(someDate, body);
}

private Task<IActionResult> Method1(DateTime someDate, [Required [FromBody] SomeModel body)
{
  // do stuff
}

private Task<IActionResult> Method2(DateTime someDate, [Required [FromBody] SomeModel body)
{
  // do stuff
}

I am getting an AD0001 on the declaration line of Method1 and another for Method2

How can I resolve this? I have seen other reports of AD0001 (for different reasons( and suggested “solutions” describe how to disable the warning for this - but that is hiding the problem rather than resolving it.

Hey there,

It looks like you’ve filed this question through your Enterprise Support as well. Please don’t cross-post – that’s double the effort on our side. :slight_smile:

We’ll handle this through ServiceDesk, and if it gets solved, we’ll come back with the answer so the community can also benefit!

1 Like

Hi - I posted here first but got no answer and then posted in our paid for support after about a week.
My preference is to use the forums both because others may be able to offer assistance and so that others can benefit from the answer…but at the end of the day, we need support so I posted there in the hope that someone would take a look.

It is only double the effort on your part if you make any effort at all :slight_smile:

I looked into this and the minimum code to reproduce the bug is

var (_, (_, _)) = (1, (2, 3));

I will try to find the root cause for this. Until then you can replace the designation deconstruction with tuple deconstruction to fix the issue like in one of the following ways:

(var a, (var b, var c)) = (1, (2, 3));
(var _, (var _, var _)) = (1, (2, 3));
(_, (_, _)) = (1, (2, 3));
_ = (1, (2, 3));
1 Like

Thanks @Martin_Strecker - the first form did the job.
Would appreciate if you can update this thread (or the support ticket) when you have a resolution to the issue rather than a workaround.

After adding the workaround, I have to suppress Resharper telling me to refactor the offending line of code and will then have to tell SonarQube to ignore the suppression :slight_smile:

Hi @tbutler,

I’m glad to hear that the workaround fixes the problem. And I’m sorry to hear that the workaround causes new issues. A fix is in the works: SE: Fix ArgumentNullException for nested designations by martin-strecker-sonarsource · Pull Request #5828 · SonarSource/sonar-dotnet · GitHub, and you can follow its progress at GitHub.

magic, thanks.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

The issue is fixed and released.

2 Likes