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.Setter with 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
MyColorProperty field 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 the MyColorProperty field
- Field is not found → returns
null
SetterValueProvider.TryProvideValue() calls bpRef.ToFQDisplayString() with null
ISymbolExtensions.ToFQDisplayString() has no type pattern matching null → throws NotImplementedException
Key code path:
SetterValueProvider.cs:54 → bpNode.GetBindableProperty(context) returns null
SetterValueProvider.cs:64 → bpRef.ToFQDisplayString() called with null
ISymbolExtensions.cs:24 → throws NotImplementedException (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)
Description
The XAML Source Generator (XSG) throws
NotImplementedExceptionwith errorMAUIG1001when processing aStyle.Setterthat uses a markup extension (like{StaticResource}) on a partial property decorated with CommunityToolkit.MAUI's[BindableProperty]attribute.Steps to Reproduce
[BindableProperty]:Style.Setterwith a markup extension targeting that property:dotnet build -f net10.0-androidExpected Behavior
The XAML Source Generator should either:
Actual Behavior
Build fails with:
The
MainPage.xaml.xsg.csfile is not generated at all.Root Cause Analysis
The bug occurs because source generators run in isolation and in parallel:
MyColorPropertyfield from the[BindableProperty]attribute<Setter Property="MyColor" Value="{StaticResource TestColor}" />:NodeSGExtensions.GetBindableProperty()looks for theMyColorPropertyfieldnullSetterValueProvider.TryProvideValue()callsbpRef.ToFQDisplayString()with nullISymbolExtensions.ToFQDisplayString()has no type pattern matchingnull→ throwsNotImplementedExceptionKey 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:
Or manually define the BindableProperty field so XSG can see it.
Version Information
[BindableProperty]attributeRelated
Discord converstaion: https://discord.com/channels/1351511037215772672/1433378741832122458/1463986720981778432
Repro project: https://github.com/tranb3r/Issues/tree/main/MauiAppTestXamlSG
/cc @tranb3r (original reporter)