-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Version Used: Visual Studio 2022 Professional 17.12.1 - and whatever Roslyn version is included. ALso using ReSharper.
Steps to Reproduce:
Not sure about the exact steps as I cannot post the actual source code here and won't bother to try too hard to locate the problem, but here's a rough description of what I did.
I had (have) a lambda defined in a rather long method and placed in a variable. It takes an object reference as a parameter and is used to call a delegate using the parameter, among other things, and then return the object. So I have something like this:
var callStuffAndReturn = (FancyClass fancy) => { do stuff... return fancy; }
so I can do this in a couple of places without repeating myself:
return callStuffAndReturn(aThing)
Yeah I know I could implement this using a local method, but this is what crashed the code analysis so that's what I'm reporting.
After implementing this I started getting "Feature 'Diagnostic analyzer runner' is currently unavailable due to an internal error." The stack trace looks like this:
StreamJsonRpc.RemoteInvocationException: Specified argument was out of the range of valid values. (Parameter 'character') at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__1561.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.BrokeredServiceConnection1.<TryInvokeAsync>d__181.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(TextDocument document, Location location)
at Microsoft.CodeAnalysis.Diagnostics.DiagnosticData.Create(Diagnostic diagnostic, TextDocument document)
at Microsoft.CodeAnalysis.Workspaces.Diagnostics.DiagnosticAnalysisResultBuilder.AddDocumentDiagnostic(Dictionary2& map, TextDocument document, Diagnostic diagnostic) at Microsoft.CodeAnalysis.Workspaces.Diagnostics.DiagnosticAnalysisResultBuilder.AddDiagnostic(Dictionary2& lazyLocals, SyntaxTree tree, Diagnostic diagnostic)
at Microsoft.CodeAnalysis.Workspaces.Diagnostics.DiagnosticAnalysisResultBuilder.AddDiagnostics(Dictionary2& lazyLocals, SyntaxTree tree, IEnumerable1 diagnostics)
at Microsoft.CodeAnalysis.Diagnostics.Extensions.g__AddDiagnosticsToResult|7_1(ImmutableArray1 diagnostics, DiagnosticAnalysisResultBuilder& result, Compilation compilation, SyntaxTree tree, DocumentId additionalDocumentId, Nullable1 span, AnalysisKind kind, ImmutableArray1 diagnosticIdsToFilter, Boolean includeSuppressedDiagnostics) at Microsoft.CodeAnalysis.Diagnostics.Extensions.ToResultBuilderMapAsync(AnalysisResult analysisResult, ImmutableArray1 additionalPragmaSuppressionDiagnostics, DocumentAnalysisScope documentAnalysisScope, Project project, VersionStamp version, Compilation compilation, ImmutableArray1 analyzers, SkippedHostAnalyzersInfo skippedAnalyzersInfo, Boolean includeSuppressedDiagnostics, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Remote.Diagnostics.DiagnosticComputer.AnalyzeAsync(CompilationWithAnalyzersPair compilationWithAnalyzers, BidirectionalMap2 analyzerToIdMap, ImmutableArray1 projectAnalyzers, ImmutableArray1 hostAnalyzers, SkippedHostAnalyzersInfo skippedAnalyzersInfo, Boolean reportSuppressedDiagnostics, Boolean logPerformanceInfo, Boolean getTelemetryInfo, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.Diagnostics.DiagnosticComputer.GetDiagnosticsAsync(ImmutableArray1 projectAnalyzerIds, ImmutableArray1 hostAnalyzerIds, Boolean reportSuppressedDiagnostics, Boolean logPerformanceInfo, Boolean getTelemetryInfo, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.Diagnostics.DiagnosticComputer.GetNormalPriorityDiagnosticsAsync(ImmutableArray1 projectAnalyzerIds, ImmutableArray1 hostAnalyzerIds, Boolean reportSuppressedDiagnostics, Boolean logPerformanceInfo, Boolean getTelemetryInfo, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.RemoteDiagnosticAnalyzerService.<>c__DisplayClass3_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass7_01.<<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, Func2 implementation, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Boolean updatePrimaryBranch, Func2 implementation, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func2 implementation, CancellationToken cancellationToken)
at Microsoft.CodeAnalysis.Remote.RemoteDiagnosticAnalyzerService.CalculateDiagnosticsAsync(Checksum solutionChecksum, DiagnosticArguments arguments, CancellationToken cancellationToken)
`
Expected Behavior:
Code analysis doesn't crash.
Actual Behavior:
Code analysis crashes due to ArgumentOutOfRangeException.
Workaround:
Convert to a local method. Then it doesn't crash.