Random error with SonarAnalyzer

Hello,

We are using SonarAnalyzer.CSharp version 8.26.0.34506 as nuget package and when randomly analyze our code it throws this exception:

CSC : error AD0001: Analyzer 'SonarAnalyzer.Rules.CSharp.StringConcatenationInLoop' threw an exception of type 
'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'. 

CSC : error AD0001: Analyzer 'SonarAnalyzer.Rules.SymbolicExecution.SymbolicExecutionRunner' threw an exception of type 
'SonarAnalyzer.SymbolicExecution.SymbolicExecutionException' with message 'Error processing method: 
BindModelAsync ## Method file: C:\xxxxxxxxxxx.cs ## 
Method line: xxxx ## Inner exception: System.NullReferenceException: Object reference not set to an instance of an object. ##    
at Microsoft.CodeAnalysis.CSharp.SymbolDisplayVisitor.AddTupleTypeName(INamedTypeSymbol symbol) ##    
at Microsoft.CodeAnalysis.CSharp.SymbolDisplayVisitor.AddNameAndTypeArgumentsOrParameters(INamedTypeSymbol symbol) ##   
at Microsoft.CodeAnalysis.CSharp.SymbolDisplayVisitor.MinimallyQualify(INamedTypeSymbol symbol) ##    
at Microsoft.CodeAnalysis.CSharp.SymbolDisplayVisitor.VisitNamedTypeWithoutNullability(INamedTypeSymbol symbol) ##    
at Microsoft.CodeAnalysis.CSharp.SymbolDisplayVisitor.VisitNamedType(INamedTypeSymbol symbol) ##    
at Microsoft.CodeAnalysis.CSharp.SymbolDisplay.ToDisplayParts(ISymbol symbol, SemanticModel semanticModelOpt, Int32 positionOpt, SymbolDisplayFormat format, Boolean minimal) ##    
at Microsoft.CodeAnalysis.CSharp.Symbols.PublicModel.Symbol.Microsoft.CodeAnalysis.ISymbol.ToDisplayString(SymbolDisplayFormat format) ##    
at SonarAnalyzer.Helpers.TypeHelper.IsMatch(ITypeSymbol typeSymbol, KnownType type) ##    
at SonarAnalyzer.SymbolicExecution.SymbolicValue.Create(ITypeSymbol type) ##    
at SonarAnalyzer.SymbolicExecution.CSharpExplodedGraph.VisitTuple(TupleExpressionSyntaxWrapper tuple, ProgramState programState) ##    
at SonarAnalyzer.SymbolicExecution.CSharpExplodedGraph.VisitInstruction(ExplodedGraphNode node) ##    
at SonarAnalyzer.SymbolicExecution.AbstractExplodedGraph.Walk() ##    
at SonarAnalyzer.Rules.SymbolicExecution.SymbolicExecutionRunner.Analyze(CSharpExplodedGraph explodedGraph, SyntaxNodeAnalysisContext context) ##    
at

If we reanalyze our code it doesn’t show the error again, so we haven’t found a way to always reproduce it

Hi, we constantly improve our analyzers and fix lots of bugs, false positives etc. Could you please update to the latest ( 8.35 ) and let us know if it reproduces?

Thanks!

Hi,

We have update the version and the error persist. We have detected four different errors:

  • InsecureEncryptionAlgorithm
  • StringConcatenationInLoop
  • PureAttributeOnVoidMethod
  • SymbolicExecutionRunner

We have run several times a build getting 2/10 failed builds.
Looking for these errors we have deactivated the following rules:

  • S1643
  • S2259
  • S3603
  • S5547

Now we have got 0/30 failed builds.
We hope this can serve as a clue.

Thanks.

Thanks for the reply, @eugeniolt !

This seems to be related to the following bug in the Roslyn compiler: ISymbol.ToDisplayString throws NullReferenceException in SymbolDisplayVisitor · Issue #53943 · dotnet/roslyn · GitHub

Unfortunately they need to fix it in a future version of the compiler.

Until then, you can ignore the AD0001 error in your builds (see comment).