Summary
#34408 ("[XAML] SourceGen: Compile RelativeSource AncestorType bindings under AOT") introduced a false-positive MAUIG2045 diagnostic for RelativeSource AncestorType bindings whose runtime ancestor is a derived type.
Repro
src/Controls/samples/Controls.Sample — e.g. Pages/ControlsPage.xaml(49,14):
SelectedItem="{Binding SelectedItem, Source={x:RelativeSource AncestorType={x:Type ContentPage}}, Mode=TwoWay}"
error MAUIG2045: Binding: Property "SelectedItem" not found on
"global::Microsoft.Maui.Controls.ContentPage". The binding will use slower
reflection-based binding at runtime.
The XAML root is views:BasePage, and BasePage : ContentPage declares both NavigateCommand and SelectedItem. At runtime the resolved ancestor is a BasePage, so the binding is valid — the diagnostic is wrong.
23 diagnostics across 12 XAML files in that one sample.
Cause
src/Controls/src/SourceGen/KnownMarkups.cs (added in #34408) resolves TryGetRelativeSourceAncestorType(...) and then does dataTypeSymbol = ancestorTypeSymbol, validating the property against the declared AncestorType. Because AncestorType matching is an is-style check, any derived type is a legal runtime match, so absence of the property on the declared type does not imply the binding is broken.
Impact
Fires for any consumer using RelativeSource AncestorType with a derived page/view type — a very common pattern. MAUIG2045 is declared Warning severity (src/Controls/src/SourceGen/AnalyzerReleases.Unshipped.md:24), so it only breaks builds where warnings are errors — which is exactly what SampleTests.cs:39 does (TreatWarningsAsErrors=true).
CI evidence
Regressed the Samples windows and Samples macOS integration-test legs on net11.0:
Failing test: Microsoft.Maui.IntegrationTests.SampleTests.Build(relativeProj: "src\Controls\samples\Controls.Sample\Maui.Controls.Sample.csproj", config: "Debug"|"Release").
Current mitigation (must be reverted)
MAUIG2045 was added to <NoWarn> in Maui.Controls.Sample.csproj to unblock the .NET 11 Preview 7 cut. This only hides it in our sample — customers still hit the false positive. Remove the NoWarn entry as part of the real fix.
Suggested fix
Suppress BindingPropertyNotFound when the property is absent from the AncestorType but that type is unsealed, since a derived runtime ancestor may declare it.
Summary
#34408("[XAML] SourceGen: Compile RelativeSource AncestorType bindings under AOT") introduced a false-positiveMAUIG2045diagnostic forRelativeSource AncestorTypebindings whose runtime ancestor is a derived type.Repro
src/Controls/samples/Controls.Sample— e.g.Pages/ControlsPage.xaml(49,14):SelectedItem="{Binding SelectedItem, Source={x:RelativeSource AncestorType={x:Type ContentPage}}, Mode=TwoWay}"The XAML root is
views:BasePage, andBasePage : ContentPagedeclares bothNavigateCommandandSelectedItem. At runtime the resolved ancestor is aBasePage, so the binding is valid — the diagnostic is wrong.23 diagnostics across 12 XAML files in that one sample.
Cause
src/Controls/src/SourceGen/KnownMarkups.cs(added in #34408) resolvesTryGetRelativeSourceAncestorType(...)and then doesdataTypeSymbol = ancestorTypeSymbol, validating the property against the declaredAncestorType. BecauseAncestorTypematching is anis-style check, any derived type is a legal runtime match, so absence of the property on the declared type does not imply the binding is broken.Impact
Fires for any consumer using
RelativeSource AncestorTypewith a derived page/view type — a very common pattern.MAUIG2045is declared Warning severity (src/Controls/src/SourceGen/AnalyzerReleases.Unshipped.md:24), so it only breaks builds where warnings are errors — which is exactly whatSampleTests.cs:39does (TreatWarningsAsErrors=true).CI evidence
Regressed the
Samples windowsandSamples macOSintegration-test legs onnet11.0:Failing test:
Microsoft.Maui.IntegrationTests.SampleTests.Build(relativeProj: "src\Controls\samples\Controls.Sample\Maui.Controls.Sample.csproj", config: "Debug"|"Release").Current mitigation (must be reverted)
MAUIG2045was added to<NoWarn>inMaui.Controls.Sample.csprojto unblock the .NET 11 Preview 7 cut. This only hides it in our sample — customers still hit the false positive. Remove theNoWarnentry as part of the real fix.Suggested fix
Suppress
BindingPropertyNotFoundwhen the property is absent from theAncestorTypebut that type is unsealed, since a derived runtime ancestor may declare it.