Skip to content

HR fails when removing a property with an initializer from a partial class #79320

@dr1rrb

Description

@dr1rrb

Version Used: net 9.0 / Microsoft.CodeAnalysis 4.14.0

Steps to Reproduce:

  1. Start the repro project RoslynOutOfRange.zip with debugger attached
  2. In the file MainPage.g.cs comment the line 11 private object _component_0_Holder { get; set; } = new();
  3. Invoke HR
  4. Observe error
    error ENC1002: Cannot apply changes -- unexpected error: 'Index was outside the bounds of the array.'
Image

Diagnostic Id: ENC1002

Expected Behavior:
Able to apply changes using hot-reload.

Actual Behavior:
error ENC1002: Cannot apply changes -- unexpected error: 'Index was outside the bounds of the array.'

Note: This happens only if we have a call like MyStaticClass.Configure(something => { }); in the "main" class/file. If this line is commented out, the error will not happen.

Note 2: The partial class has to be in a different file from the "main", having them both in the same file will also avoid the error.

Workaround:
Initialize the property in the constructor instead of using an initializer.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions