-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
The XAML Source Generator (XSG) throws NotImplementedException with error MAUIG1001 when processing a Style.Setter that uses a markup extension (like {StaticResource}) on a partial property decorated with CommunityToolkit.MAUI's [BindableProperty] attribute.
Steps to Reproduce
- Create a .NET MAUI app targeting .NET 10
- Add CommunityToolkit.Maui package
- Create a custom control with a partial property using
[BindableProperty]:
using CommunityToolkit.Maui.GeneratedBindableProperty;
public partial class MyLabel : Label
{
[BindableProperty]
public partial Color MyColor { get; set; }
}- In XAML, use a
Style.Setterwith a markup extension targeting that property:
<ContentPage.Resources>
<Color x:Key="TestColor">Red</Color>
<Style TargetType="local:MyLabel">
<Setter Property="MyColor" Value="{StaticResource TestColor}" />
</Style>
</ContentPage.Resources>- Build with:
dotnet build -f net10.0-android
Expected Behavior
The XAML Source Generator should either:
- Successfully generate code for the Style Setter
- Or produce a clear diagnostic explaining that the BindableProperty field is not visible
Actual Behavior
Build fails with:
error MAUIG1001: An error occured while parsing Xaml: The method or operation is not implemented.
The MainPage.xaml.xsg.cs file is not generated at all.
Root Cause Analysis
The bug occurs because source generators run in isolation and in parallel:
- CommunityToolkit.MAUI's source generator creates
MyColorPropertyfield from the[BindableProperty]attribute - XAML Source Generator (XSG) runs in parallel and sees only the original compilation (without other SG's output)
- When XSG processes
<Setter Property="MyColor" Value="{StaticResource TestColor}" />:NodeSGExtensions.GetBindableProperty()looks for theMyColorPropertyfield- Field is not found → returns
null SetterValueProvider.TryProvideValue()callsbpRef.ToFQDisplayString()with nullISymbolExtensions.ToFQDisplayString()has no type pattern matchingnull→ throwsNotImplementedException
Key code path:
SetterValueProvider.cs:54→bpNode.GetBindableProperty(context)returns nullSetterValueProvider.cs:64→bpRef.ToFQDisplayString()called with nullISymbolExtensions.cs:24→ throwsNotImplementedException(no pattern matches null)
Workaround
Use simple values instead of markup extensions:
<!-- Works -->
<Setter Property="MyColor" Value="Red" />
<!-- Fails -->
<Setter Property="MyColor" Value="{StaticResource TestColor}" />Or manually define the BindableProperty field so XSG can see it.
Version Information
- .NET 10 Preview
- CommunityToolkit.Maui with
[BindableProperty]attribute
Related
Discord converstaion: https://discord.com/channels/1351511037215772672/1433378741832122458/1463986720981778432
Repro project: https://github.com/tranb3r/Issues/tree/main/MauiAppTestXamlSG
/cc @tranb3r (original reporter)