- Operating system: Windows 10
- Visual Studio version: 17.8.0
- SonarLint plugin version: 7.4.0.80741
- Programming language you’re coding in: C# (.Net Framework 4.8)
- Is connected mode used: No
- Connected to SonarCloud or SonarQube (and which version):
I have enabled SonarLint on Visual studio with an existing project which has the “Warning as Errors” switched on, and it has many detected Sonar issues which can’t be resolved in one go.
The suggested solution to this (How to exclude sonar lint warnings from - build settings (Treat warnings as error) in project (visual studio) ) is to have use the “WarningsNotAsErrors” with the excluded rules.
To get started I have added all numbers from S1 to S10000 , which works in terms of moving the items from the error to the warning.
However there are several rules that come up with an AD0001 warning saying that the analyzer has had an exception. These exceptions do not happen if I let them appear as errors (e.g. I have several S2259 as errors but none when I have them as warnings). I also get the correct results if I switch of TreatWarningsAsErrors.
The list of exceptions are:
Rules S1944, S2053, S2222, S2259, S2583, S2589, S3329, S3655, S3900, S3949, S3966, S4158, S5773
System.ArgumentNullException: Value cannot be null. (Parameter 'type')
at SonarAnalyzer.SymbolicExecution.Roslyn.ExceptionState..ctor(ITypeSymbol type)
at SonarAnalyzer.SymbolicExecution.Roslyn.ExceptionCandidate.FromConversion(IOperationWrapperSonar operation)
at SonarAnalyzer.SymbolicExecution.Roslyn.ExceptionCandidate.FromOperation(ProgramState state, IOperationWrapperSonar operation)
at SonarAnalyzer.SymbolicExecution.Roslyn.RoslynSymbolicExecution.ProcessOperation(ExplodedNode node)+MoveNext()
at SonarAnalyzer.SymbolicExecution.Roslyn.RoslynSymbolicExecution.Execute()
at SonarAnalyzer.Rules.SymbolicExecutionRunnerBase.AnalyzeRoslyn(SonarAnalysisContext analysisContext, SonarSyntaxNodeReportingContext nodeContext, SyntaxNode body, ISymbol symbol)
Rule S1871
System.NullReferenceException: Object reference not set to an instance of an object.
at SonarAnalyzer.Extensions.InvocationExpressionSyntaxExtensions.IsEqualTo(InvocationExpressionSyntax first, InvocationExpressionSyntax second, SemanticModel model)
at SonarAnalyzer.Rules.CSharp.ConditionalStructureSameImplementation.HaveTheSameInvocations(SyntaxList`1 first, SyntaxList`1 second, SemanticModel model)
at SonarAnalyzer.Rules.CSharp.ConditionalStructureSameImplementation.<>c__DisplayClass5_0.<Initialize>b__2(SwitchSectionSyntax preceding)
at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
at SonarAnalyzer.Rules.CSharp.ConditionalStructureSameImplementation.<>c.<Initialize>b__5_1(SonarSyntaxNodeReportingContext c)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
Rule S6588
System.NullReferenceException: Object reference not set to an instance of an object.
at SonarAnalyzer.Rules.UseUnixEpochBase`3.IsUnixEpochSupported(Compilation compilation)
at SonarAnalyzer.Rules.UseUnixEpochBase`3.<>c__DisplayClass10_0.<Initialize>b__0(SonarCompilationStartAnalysisContext start)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
Rule S6618
System.NullReferenceException: Object reference not set to an instance of an object.
at SonarAnalyzer.Rules.CSharp.UseStringCreate.CompilationTargetsValidNetVersion(Compilation compilation)
at SonarAnalyzer.Rules.CSharp.UseStringCreate.<>c__DisplayClass6_0.<Initialize>b__0(SonarCompilationStartAnalysisContext start)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
Rule S6610
System.NullReferenceException: Object reference not set to an instance of an object.
at SonarAnalyzer.Rules.UseCharOverloadOfStringMethodsBase`2.CompilationTargetsValidNetVersion(Compilation compilation)
at SonarAnalyzer.Rules.UseCharOverloadOfStringMethodsBase`2.<Initialize>b__5_0(SonarCompilationStartAnalysisContext start)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken)
Is there anything that I can do to avoid the exceptions without changing the behavior for the other analyzers?