Repository navigation
Description
Description
Replacing a XAML element with x:Name with a different named element during a running .NET MAUI Hot Reload session has been reported to produce ENC0020: Renaming field 'count' requires restarting the application. The user removed an element and added another; they did not explicitly rename a field in C#. The diagnostic appears against MainPage.xaml.cs. This needs a minimal reproduction to establish the affected MAUI/IDE/runtime versions, platform(s), and whether the failure is in XAML Hot Reload, C# Hot Reload of generated code, or their interaction.
MAUI's code-behind generator emits fields for named XAML elements. Roslyn rejects field renames and deletions, but handles auto-property renames as deleting the old property/accessors and adding new ones when the runtime supports adding instance fields. Deleting an auto-property leaves its backing field in the running type. Both CoreCLR and Mono advertise AddInstanceFieldToExistingType, but this does not establish that replacing named MAUI XAML elements works end-to-end; the runtime instance-field update test is currently skipped on Mono.
Investigate whether opt-in generated auto-properties (or another stable access mechanism) permit this edit without a restart. Account for existing field-based code-behind API and x:FieldModifier, runtime InitializeComponent, XAML source generation, and XamlC's SetFieldVisitor, which currently writes fields. Verify existing page instances and namescopes after replacement, not just absence of the diagnostic. A global field-to-property switch would be a compatibility change; do not assume it is safe. Related but distinct stale-reference behavior: #5731.
Steps to Reproduce
Reported sequence (not yet independently reproduced):
- Run a MAUI page containing a named element (for example
<Label x:Name="count" />) with Hot Reload enabled. - Remove that element and add a different element with a different
x:Namewhile the app is running. - Apply the edit and inspect Hot Reload output.
Expected: the edit is applied without a misleading field-rename diagnostic, if supported by the runtime; otherwise provide an accurate, actionable reason for requiring restart.
Actual reported: ENC0020 claims a generated field was renamed and requires restarting the app.
Link to public reproduction project repository
dotnet new maui and then rename the x:Name="count".
Version with bug
.NET 11 RC 2 (unreleased builds at the time)
Is this a regression from previous behavior?
No
Last version that worked well
None
Affected platforms
All
Affected platform versions
N/A
Did you find any workaround?
Restart the application after replacing named XAML elements. Avoid removing/adding x:Name during a Hot Reload session when a restart is unacceptable.
Relevant log output
2026-09-29 11:51:00.739 [error] MainPage.xaml.cs(16,2): error ENC0020: Renaming field 'count' requires restarting the application.
Activity
jonathanpeppers commentedon Sep 29, 2026
Another version of the "rude edit" is by removing an
x:Name:StephaneDelcroix commentedon Oct 5, 2026
we could modify the code behind generator so it doesn't remove fields. that would keep it coherent, and keep x:Name backed up by fields, not props
Make CodeBehind generator incremental to fix EnC rude edits on x:Name…
github-actions commentedon Oct 20, 2026
Closed by #39281 (merged to
net11.0). GitHub only auto-closes for PRs merged to the default branch; this issue was fixed by a PR merged to a non-default branch.