[XSG] Fix Setter.Value property element lookup for MauiGlobalUri namespace#34055
Merged
StephaneDelcroix merged 3 commits intomainfrom Feb 25, 2026
Merged
[XSG] Fix Setter.Value property element lookup for MauiGlobalUri namespace#34055StephaneDelcroix merged 3 commits intomainfrom
StephaneDelcroix merged 3 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a .NET MAUI XAML Source Generator (XSG) regression where Setter instances using the <Setter.Value> property element could be dropped (and therefore not added to Trigger.Setters) when implicit/alternative xmlns declarations caused the Value property element’s namespace URI to differ from the previously hard-coded lookups.
Changes:
- Update
SetterValueProvider.GetValueNode()to locate theValueproperty element byLocalName == "Value"regardless of namespace URI. - Add a SourceGen unit test reproducing the issue with implicit xmlns and verifying the generated code contains the
Setters.Add(...)call.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Controls/src/SourceGen/SetterValueProvider.cs | Makes <Setter.Value> lookup namespace-agnostic so XSG doesn’t drop setters when property-element namespaces vary. |
| src/Controls/tests/SourceGen.UnitTests/InitializeComponent/SetterValueInTrigger.cs | Adds a regression test covering <Setter.Value> inside a Trigger under implicit xmlns conditions. |
9112516 to
18b8211
Compare
88c0264 to
6aef93f
Compare
Fixes #34039 When <Setter.Value> is used as a property element with a namespace URI other than MauiUri (e.g., MauiGlobalUri with implicit xmlns), GetValueNode() failed to find it. Since PR #33681 changed the null return to a skip sentinel, this caused the Setter to be removed from Variables entirely, preventing the .Add() call from being generated. The fix makes GetValueNode() iterate all properties matching LocalName == "Value" instead of checking specific namespace URIs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…gger Verifies that Setter with <Setter.Value> containing FontImageSource inside a Style Trigger is correctly inflated across all XamlInflator modes (Runtime, XamlC, SourceGen). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
6aef93f to
d614d1c
Compare
jfversluis
approved these changes
Feb 25, 2026
kubaflo
approved these changes
Feb 25, 2026
jfversluis
pushed a commit
to yuriikyry4enko/maui
that referenced
this pull request
Feb 26, 2026
…space (dotnet#34055) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ## Description Fixes dotnet#34039 When `<Setter.Value>` is used as a property element, `GetValueNode()` in `SetterValueProvider.cs` looked up the `Value` property only by two specific namespace URIs (`""` and `MauiUri`). When the property element resolved to `MauiGlobalUri` instead, the lookup returned null. Since PR dotnet#33681 changed the null-return behavior to a skip sentinel, this caused the Setter to be removed from `Variables` entirely, preventing the `.Add()` call from being generated. ### Root Cause `GetValueNode()` checked only two namespace URIs: ```csharp node.Properties.TryGetValue(new XmlName("", "Value"), out valueNode) node.Properties.TryGetValue(new XmlName(XamlParser.MauiUri, "Value"), out valueNode) ``` Property elements like `<Setter.Value>` inherit their namespace URI from the XML reader, which varies depending on the xmlns declaration used. When the XAML used `MauiGlobalUri`, neither existing check matched, so `GetValueNode()` returned null, triggering the skip sentinel introduced in dotnet#33681, which suppressed the `Setters.Add()` call. ### Fix Added `MauiGlobalUri` as a third namespace to check in the `GetValueNode()` lookup chain: ```csharp !node.Properties.TryGetValue(new XmlName("", "Value"), out valueNode) && !node.Properties.TryGetValue(new XmlName(XamlParser.MauiUri, "Value"), out valueNode) && !node.Properties.TryGetValue(new XmlName(XamlParser.MauiGlobalUri, "Value"), out valueNode) && ``` ### Testing - Added XAML unit test (`Maui34039`) verifying Setter with property element value in a Trigger - Added SourceGen unit test (`SetterValueInTrigger`) verifying correct codegen - Tests fail without fix, pass with fix --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TamilarasanSF4853
pushed a commit
to TamilarasanSF4853/maui
that referenced
this pull request
Mar 2, 2026
…space (dotnet#34055) <!-- Please let the below note in for people that find this PR --> > [!NOTE] > Are you waiting for the changes in this PR to be merged? > It would be very helpful if you could [test the resulting artifacts](https://github.com/dotnet/maui/wiki/Testing-PR-Builds) from this PR and let us know in a comment if this change resolves your issue. Thank you! ## Description Fixes dotnet#34039 When `<Setter.Value>` is used as a property element, `GetValueNode()` in `SetterValueProvider.cs` looked up the `Value` property only by two specific namespace URIs (`""` and `MauiUri`). When the property element resolved to `MauiGlobalUri` instead, the lookup returned null. Since PR dotnet#33681 changed the null-return behavior to a skip sentinel, this caused the Setter to be removed from `Variables` entirely, preventing the `.Add()` call from being generated. ### Root Cause `GetValueNode()` checked only two namespace URIs: ```csharp node.Properties.TryGetValue(new XmlName("", "Value"), out valueNode) node.Properties.TryGetValue(new XmlName(XamlParser.MauiUri, "Value"), out valueNode) ``` Property elements like `<Setter.Value>` inherit their namespace URI from the XML reader, which varies depending on the xmlns declaration used. When the XAML used `MauiGlobalUri`, neither existing check matched, so `GetValueNode()` returned null, triggering the skip sentinel introduced in dotnet#33681, which suppressed the `Setters.Add()` call. ### Fix Added `MauiGlobalUri` as a third namespace to check in the `GetValueNode()` lookup chain: ```csharp !node.Properties.TryGetValue(new XmlName("", "Value"), out valueNode) && !node.Properties.TryGetValue(new XmlName(XamlParser.MauiUri, "Value"), out valueNode) && !node.Properties.TryGetValue(new XmlName(XamlParser.MauiGlobalUri, "Value"), out valueNode) && ``` ### Testing - Added XAML unit test (`Maui34039`) verifying Setter with property element value in a Trigger - Added SourceGen unit test (`SetterValueInTrigger`) verifying correct codegen - Tests fail without fix, pass with fix --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
Description
Fixes #34039
When
<Setter.Value>is used as a property element,GetValueNode()inSetterValueProvider.cslooked up theValueproperty only by two specific namespace URIs (""andMauiUri). When the property element resolved toMauiGlobalUriinstead, the lookup returned null. Since PR #33681 changed the null-return behavior to a skip sentinel, this caused the Setter to be removed fromVariablesentirely, preventing the.Add()call from being generated.Root Cause
GetValueNode()checked only two namespace URIs:Property elements like
<Setter.Value>inherit their namespace URI from the XML reader, which varies depending on the xmlns declaration used. When the XAML usedMauiGlobalUri, neither existing check matched, soGetValueNode()returned null, triggering the skip sentinel introduced in #33681, which suppressed theSetters.Add()call.Fix
Added
MauiGlobalUrias a third namespace to check in theGetValueNode()lookup chain:Testing
Maui34039) verifying Setter with property element value in a TriggerSetterValueInTrigger) verifying correct codegen