Skip to content

Comments

Fix XSG crash when Style Setter uses markup extension with source-generated BindableProperty#33836

Merged
PureWeen merged 1 commit intomainfrom
dev/simonrozsival/fix-bug-failing-xsg-rebased
Feb 11, 2026
Merged

Fix XSG crash when Style Setter uses markup extension with source-generated BindableProperty#33836
PureWeen merged 1 commit intomainfrom
dev/simonrozsival/fix-bug-failing-xsg-rebased

Conversation

@simonrozsival
Copy link
Member

@simonrozsival simonrozsival commented Feb 2, 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 #33835

This PR fixes a remaining gap in the XSG handling of source-generated bindable properties (from CommunityToolkit.MAUI [BindableProperty] attribute) — specifically when markup extensions like {StaticResource} are used in Style Setters.

Background

PR #33562 fixed Style Setters with simple literal values on source-generated bindable properties. However, when the Setter value uses a markup extension (e.g., {StaticResource TestColor}), a different code path is taken:

  1. SetterValueProvider.CanProvideValue() returns false for markup extensions
  2. The Setter goes through the standard processing path via BindablePropertyConverter
  3. BindablePropertyConverter calls GetBindableProperty() which returns null (field not visible to XSG)
  4. This causes MAUIG1001: The method or operation is not implemented

Changes

  • NodeSGExtensions.GetBindableProperty(ValueNode): Changed return type to IFieldSymbol? (nullable) — returns null instead of throwing when the bindable property field is not found
  • BindablePropertyConverter: Added heuristic fallback to detect [BindableProperty] attributes and construct the BP reference, matching the approach already used in SetterValueProvider
  • Tests: Added SourceGen unit tests and XAML unit tests covering the markup extension scenario

Review Note

The Copilot reviewer comment about missing TestColor resource was incorrect — the resource IS defined in both tests that reference it. The 3rd test uses a simple string value and correctly does not define it.

@simonrozsival simonrozsival added area-xaml XAML, CSS, Triggers, Behaviors xsg Xaml sourceGen labels Feb 2, 2026
@simonrozsival simonrozsival added this to the .NET 10 SR5 milestone Feb 2, 2026
@simonrozsival simonrozsival marked this pull request as ready for review February 2, 2026 13:24
Copilot AI review requested due to automatic review settings February 2, 2026 13:24
Copy link
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 crash in the XAML Source Generator (XSG) when Style.Setter targets a partial property decorated with the [BindableProperty] attribute from CommunityToolkit.MAUI. The issue occurs because source generators run in isolation - when XSG processes the XAML, it cannot see the BindableProperty field generated by another source generator running in parallel.

Changes:

  • Made GetBindableProperty return nullable and updated all call sites to handle null gracefully
  • Added heuristic detection logic to identify properties with [BindableProperty] attributes even when the generated field is not visible
  • Added fallback logic in SetterValueProvider to construct BindableProperty references from type and property name
  • Comprehensive test coverage for both source generator and runtime scenarios

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
NodeSGExtensions.cs Changed GetBindableProperty return type from IFieldSymbol to IFieldSymbol? to allow null returns
BindablePropertyConverter.cs Added null check and fallback to "default" when BindableProperty is not found
SetterValueProvider.cs Added heuristic fallback logic to detect [BindableProperty] attributes and construct BP references manually
ITypeSymbolExtensions.Maui.cs (not shown) Added HasBindablePropertyHeuristic method to detect properties with recognized bindable property attributes
Maui33835.xaml XAML test file with Style Setter targeting property with [BindableProperty] attribute
Maui33835.xaml.cs Runtime test verifying Style Setter works correctly with all inflators
PartialPropertyInStyleSetterTests.cs Source generator unit tests covering scenarios with/without visible BindableProperty field

@simonrozsival simonrozsival force-pushed the dev/simonrozsival/fix-bug-failing-xsg-rebased branch from c3f3fda to dc41b11 Compare February 3, 2026 19:43
@simonrozsival simonrozsival force-pushed the dev/simonrozsival/fix-bug-failing-xsg-rebased branch from dc41b11 to 16e8f2e Compare February 11, 2026 10:37
@simonrozsival simonrozsival changed the title Fix XSG crash when BindableProperty field not found Fix XSG crash when Style Setter uses markup extension with source-generated BindableProperty Feb 11, 2026
…erated BindableProperty

Fixes #33835

When a Style Setter uses a markup extension (e.g., {StaticResource}) on a
property with [BindableProperty] attribute from CommunityToolkit.MAUI,
the XSG couldn't find the BindableProperty field because it's generated
by another source generator running in parallel.

The markup extension case wasn't handled by the existing fix (#33562)
because SetterValueProvider.CanProvideValue returns false for markup
extensions, causing the Setter to go through the standard processing
path via BindablePropertyConverter, which called GetBindableProperty()
and crashed on the null result.

Fix:
- Make GetBindableProperty(ValueNode) return IFieldSymbol? (nullable)
  instead of throwing when BP field is not found
- Add heuristic fallback in BindablePropertyConverter to detect
  [BindableProperty] attributes on properties, matching the approach
  already used in SetterValueProvider
- Add tests for the markup extension scenario
@StephaneDelcroix StephaneDelcroix force-pushed the dev/simonrozsival/fix-bug-failing-xsg-rebased branch from 16e8f2e to cd46cc3 Compare February 11, 2026 12:22
@simonrozsival
Copy link
Member Author

/azp run maui-pr-devicetests,maui-pr-uitests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@PureWeen PureWeen merged commit ef0c586 into main Feb 11, 2026
159 of 162 checks passed
@PureWeen PureWeen deleted the dev/simonrozsival/fix-bug-failing-xsg-rebased branch February 11, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-xaml XAML, CSS, Triggers, Behaviors xsg Xaml sourceGen

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[XSG] XSG throws NotImplementedException when Style Setter targets partial property with [BindableProperty] attribute

3 participants