[XSG] Fix Setter.Value property element lookup to be namespace-agnostic#34055
Open
StephaneDelcroix wants to merge 2 commits intomainfrom
Open
[XSG] Fix Setter.Value property element lookup to be namespace-agnostic#34055StephaneDelcroix wants to merge 2 commits intomainfrom
StephaneDelcroix wants to merge 2 commits intomainfrom
Conversation
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>
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. |
…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>
9112516 to
18b8211
Compare
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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 specific namespace URIs (""andMauiUri). When the property element used a different namespace URI, 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 specific namespace URIs:Property elements like
<Setter.Value>inherit their namespace URI from the XML reader, which varies depending on the xmlns declaration used. When neither URI matched,GetValueNode()returned null, triggering the skip sentinel introduced in #33681 (for the OnPlatform case), which removed the Setter fromVariablesand suppressed theSetters.Add()call.Fix
Made
GetValueNode()namespace-agnostic by iterating all properties and matching onLocalName == "Value":Testing
SetterValueInTriggerunit test that reproduces the issue