dotnet / dotnet/roslyn

ArgumentOutOfRangeException in SyntaxNode.FindNode

Open
#75,014 7 comments 0 reactions 0 assignees View on GitHub
Area-Analyzers untriaged
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

I'm using the bits from 17.11.0.

Various analyzers have an `ArgumentOutOfRangeException` with the same pattern here:

https://github.com/dotnet/roslyn/blob/139f8454c7a9aca7807fe98bb760c3705559b902/src/Compilers/Core/Portable/Syntax/SyntaxNode.cs#L962-L967

`FullSpan` is contained inside `span`:
![image](https://github.com/user-attachments/assets/0e0fbe16-4dfa-464b-8b07-74b96cc37977)

Sample stack:

Microsoft.CodeAnalysis SyntaxNode.FindNode Line 966
Microsoft.CodeAnalysis.Workspaces SyntaxNodeExtensions.FindNode Line 786
Microsoft.CodeAnalysis.Workspaces AnalysisContextExtensions.GetAnalysisRoot Line 217
Microsoft.CodeAnalysis.Features SimplifyTypeNamesDiagnosticAnalyzerBase`2.AnalyzerImpl.AnalyzeCodeBlock Line 247

`context.CodeBlock` is a subspan of `context.FilterSpan` here:

https://github.com/dotnet/roslyn/blob/139f8454c7a9aca7807fe98bb760c3705559b902/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/Extensions/AnalysisContextExtensions.cs#L216-L217

![image](https://github.com/user-attachments/assets/bf7ab8c6-d343-4f4a-a7d1-2f2f3c9b40f2)

@mavasani this is pretty noisy. Just from a cursory search:

* https://github.com/dotnet/roslyn/issues/74773
* https://github.com/dotnet/roslyn/issues/74772
* https://github.com/dotnet/roslyn/issues/67932

In my case the repro was to hover over here:
https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/5e5f5f68741eb550a27c9cf1084a02dcaf914619/src/StructuredLogger/Strings/Strings.cs#L620

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.