-
Notifications
You must be signed in to change notification settings - Fork 241
Open
Labels
BugExceptions and blocking issues during analysis.Exceptions and blocking issues during analysis.
Description
Description
Running the analyzers on a generated razor / razor.cs file combo in a blazor project get's me this:
12:47:07.867 4:7>CSC : warning AD0001: Analyzer 'SonarAnalyzer.CSharp.Rules.BackslashShouldBeAvoidedInAspNetRoutes' threw an exception of type 'System.ArgumentException' with message 'Syntax node is not within syntax tree'. [/home/vsts/work/1/s/src/Project/Project.csproj]
Exception occurred with following context: (TaskId:900)
Compilation: Project (TaskId:900)
SyntaxTree: /home/vsts/work/1/s/src/Project/obj/Release/net10.0/Microsoft.CodeAnalysis.Razor.Compiler/Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator/SomeFolder_OtherFolder_SomeComponent_razor.g.cs (TaskId:900)
SyntaxNode: _elapsedTime [ArgumentSyntax]@[5942..5954) (167,110)-(167,122) (TaskId:900)
System.ArgumentException: Syntax node is not within syntax tree (TaskId:900)
at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.CheckSyntaxNode(CSharpSyntaxNode syntax) (TaskId:900)
at Microsoft.CodeAnalysis.CSharp.CSharpSemanticModel.GetTypeInfo(ExpressionSyntax expression, CancellationToken cancellationToken) (TaskId:900)
at SonarAnalyzer.CSharp.Core.Syntax.Extensions.MemberAccessExpressionSyntaxExtensionsShared.IsPtrZero(MemberAccessExpressionSyntax memberAccess, SemanticModel model) (TaskId:900)
at SonarAnalyzer.Core.Trackers.ConstantValueFinder`2.FindConstant(SyntaxNode node, HashSet`1 visitedVariables) (TaskId:900)
at SonarAnalyzer.Core.Rules.BackslashShouldBeAvoidedInAspNetRoutesBase`1.Check(SonarSyntaxNodeReportingContext c) (TaskId:900)
at SonarAnalyzer.Core.AnalysisContext.SonarCompilationStartAnalysisContext.<>c__DisplayClass18_0`1.<RegisterNodeAction>b__0(SyntaxNodeAnalysisContext x) (TaskId:900)
at Microsoft.CodeAnalysis.Diagnostics.AnalyzerExecutor.ExecuteAndCatchIfThrows_NoLock[TArg](DiagnosticAnalyzer analyzer, Action`1 analyze, TArg argument, Nullable`1 info, CancellationToken cancellationToken) (TaskId:900)
When combining the files (by using @ code inside the razor file) I don't get this issue anymore... I also tried marking the generated files as generated in the editorconfig and settings the analyzer S6930 to None in it for those files, but that didn't work either.
Scanner: SonarScanner for .NET via Azure DevOps SonarCloudPrepare@3 / SonarCloudAnalyze@3
Analyzer: SonarAnalyzer.CSharp (rule S6930), exact package version not pinned in repo because SonarCloud injects it.
Environment:
OS agent: ubuntu-latest
.NET SDK: 10.0.103
Project target: net10.0
Reproducer
Product and Version
SonarCloud
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugExceptions and blocking issues during analysis.Exceptions and blocking issues during analysis.