Skip to content

VS Diagnostic analyzer runner - ArgumentOutOfRangeException - Microsoft.CodeAnalysis.Text.LinePosition #78639

@rla-cf

Description

@rla-cf

Version Used:
Version 17.14.0

Microsoft Visual Studio Enterprise 2022 (2)
Version 17.14.0
VisualStudio.17.Release/17.14.0+36109.1
Microsoft .NET Framework
Version 4.8.09032

Installed Version: Enterprise

C# Tools 4.14.0-3.25229.6+871ef6369443071681de3351d30f41ea78ab48e6
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.

Steps to Reproduce:
When we open our solution in VS and run CodeAnalysis, (Alt-F11), VS will show this exception bar:
Image

I fear there is a certain piece of code in a large solution that is triggering this exception. (this solution compiles and runs). I can only hope there is a way to get more details about which file/line is causing this exception. Surfacing this information would make fixing this issue trivial.

StreamJsonRpc.RemoteInvocationException: Specified argument was out of the range of valid values. (Parameter 'character')
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__156`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__18`1.MoveNext()
RPC server exception:
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. (Parameter 'character')
      at Microsoft.CodeAnalysis.Text.LinePosition..ctor(Int32 line, Int32 character)
      at Microsoft.CodeAnalysis.Text.TextLineCollection.GetLinePosition(Int32 position)
      at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.GetLineSpan(TextSpan span, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.SourceLocation.GetLineSpan()
      at Microsoft.CodeAnalysis.Diagnostics.DiagnosticData.<CreateLocation>g__GetLocationInfo|30_0(FileLinePositionSpan& originalLineInfo, FileLinePositionSpan& mappedLineInfo, <>c__DisplayClass30_0&)
      at Microsoft.CodeAnalysis.Diagnostics.DiagnosticData.CreateLocation(TextDocument document, Location location)
      at Microsoft.CodeAnalysis.Diagnostics.DiagnosticData.Create(Diagnostic diagnostic, TextDocument document)
      at Microsoft.CodeAnalysis.Workspaces.Diagnostics.DiagnosticAnalysisResultBuilder.AddDocumentDiagnostic(Dictionary`2& map, TextDocument document, Diagnostic diagnostic)
      at Microsoft.CodeAnalysis.Workspaces.Diagnostics.DiagnosticAnalysisResultBuilder.AddDiagnostic(Dictionary`2& lazyLocals, SyntaxTree tree, Diagnostic diagnostic)
      at Microsoft.CodeAnalysis.Workspaces.Diagnostics.DiagnosticAnalysisResultBuilder.AddDiagnostics(Dictionary`2& lazyLocals, SyntaxTree tree, IEnumerable`1 diagnostics)
      at Microsoft.CodeAnalysis.Diagnostics.Extensions.<ToResultBuilderMapAsync>g__AddDiagnosticsToResult|8_1(ImmutableArray`1 diagnostics, DiagnosticAnalysisResultBuilder& result, SyntaxTree tree, DocumentId additionalDocumentId, Nullable`1 span, AnalysisKind kind, ImmutableArray`1 diagnosticIdsToFilter)
      at Microsoft.CodeAnalysis.Diagnostics.Extensions.ToResultBuilderMapAsync(AnalysisResultPair analysisResult, ImmutableArray`1 additionalPragmaSuppressionDiagnostics, DocumentAnalysisScope documentAnalysisScope, Project project, ImmutableArray`1 projectAnalyzers, ImmutableArray`1 hostAnalyzers, SkippedHostAnalyzersInfo skippedAnalyzersInfo, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.Diagnostics.DiagnosticComputer.AnalyzeAsync(CompilationWithAnalyzersPair compilationWithAnalyzers, BidirectionalMap`2 analyzerToIdMap, ImmutableArray`1 projectAnalyzers, ImmutableArray`1 hostAnalyzers, SkippedHostAnalyzersInfo skippedAnalyzersInfo, Boolean logPerformanceInfo, Boolean getTelemetryInfo, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.Diagnostics.DiagnosticComputer.GetDiagnosticsAsync(ImmutableArray`1 projectAnalyzerIds, ImmutableArray`1 hostAnalyzerIds, Boolean logPerformanceInfo, Boolean getTelemetryInfo, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.Diagnostics.DiagnosticComputer.GetNormalPriorityDiagnosticsAsync(ImmutableArray`1 projectAnalyzerIds, ImmutableArray`1 hostAnalyzerIds, Boolean logPerformanceInfo, Boolean getTelemetryInfo, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteDiagnosticAnalyzerService.<>c__DisplayClass3_0.<<CalculateDiagnosticsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass7_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteDiagnosticAnalyzerService.CalculateDiagnosticsAsync(Checksum solutionChecksum, DiagnosticArguments arguments, CancellationToken cancellationToken)

Expected Behavior:
Code Analyzer does not crash, and if it does, at least shows which file/line is the cause of the crash.

Actual Behavior:
Code Analyzer crashes, shows a very generic exception that is unhelpful in getting the issue resolved without an indication of the file/line/code that causes the crash.

Reviewed issues:
#78025
#76225
#51664

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions