Skip to content

[XSG] Fix Setter.Value property element lookup for MauiGlobalUri namespace#34055

Merged
StephaneDelcroix merged 3 commits intomainfrom
fix/34039-xsg-setter-value-namespace
Feb 25, 2026
Merged

[XSG] Fix Setter.Value property element lookup for MauiGlobalUri namespace#34055
StephaneDelcroix merged 3 commits intomainfrom
fix/34039-xsg-setter-value-namespace

Conversation

@StephaneDelcroix
Copy link
Copy Markdown
Contributor

@StephaneDelcroix StephaneDelcroix commented Feb 14, 2026

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() 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 #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:

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 #33681, which suppressed the Setters.Add() call.

Fix

Added MauiGlobalUri as a third namespace to check in the GetValueNode() lookup chain:

!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

Copilot AI review requested due to automatic review settings February 14, 2026 07:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 the Value property element by LocalName == "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.

@StephaneDelcroix StephaneDelcroix force-pushed the fix/34039-xsg-setter-value-namespace branch from 9112516 to 18b8211 Compare February 15, 2026 15:54
@StephaneDelcroix StephaneDelcroix changed the title [XSG] Fix Setter.Value property element lookup to be namespace-agnostic [XSG] Fix Setter.Value property element lookup for MauiGlobalUri namespace Feb 24, 2026
@StephaneDelcroix StephaneDelcroix force-pushed the fix/34039-xsg-setter-value-namespace branch from 88c0264 to 6aef93f Compare February 24, 2026 13:49
StephaneDelcroix and others added 3 commits February 25, 2026 11:21
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>
@StephaneDelcroix StephaneDelcroix force-pushed the fix/34039-xsg-setter-value-namespace branch from 6aef93f to d614d1c Compare February 25, 2026 10:21
@StephaneDelcroix StephaneDelcroix merged commit 65167b3 into main Feb 25, 2026
24 of 27 checks passed
@StephaneDelcroix StephaneDelcroix deleted the fix/34039-xsg-setter-value-namespace branch February 25, 2026 13:08
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>
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XSG drops Trigger.Setters.Add() for Shell Tab Icons when using implicit xmlns - 10.0.40

4 participants