Skip to content

'Add parameter' code fix crashes for the primary constructor of a record #54408

@jnm2

Description

@jnm2

Version Used: 16.10.2, 17.0.0-p1.1

var b = "B";
var r = new R(1, b[||]);

record R(int A);

💡 Add parameter to 'R(int)':

CSharpAddParameterCodeFixProvider crashes.

System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values.
Parameter name: index

   at Roslyn.Utilities.SpecializedCollections.Empty.List`1.get_Item(Int32 index)
   at async Microsoft.CodeAnalysis.AddParameter.AddParameterService.AddParameterAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.AddParameter.AbstractAddParameterCodeFixProvider`6.FixAsync[TArgumentSyntax,TAttributeArgumentSyntax,TArgumentListSyntax,TAttributeArgumentListSyntax,TInvocationExpressionSyntax,TObjectCreationExpressionSyntax](<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.ComputeOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.CodeActions.CodeAction.GetPreviewOperationsAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedAction.GetPreviewResultAsync(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Editor.Implementation.Suggestions.SuggestedActionWithNestedFlavors.<>c__DisplayClass11_0.<GetPreviewAsync>b__0(<Unknown Parameters>)
   at async Microsoft.CodeAnalysis.Extensions.IExtensionManagerExtensions.PerformFunctionAsync[T](<Unknown Parameters>)
   at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions