From 34956b23beddd01f24fc6d2dc54a96628d2544ab Mon Sep 17 00:00:00 2001 From: BagavathiPerumal <93652794+BagavathiPerumal@users.noreply.github.com> Date: Thu, 30 Jul 2026 18:37:54 +0530 Subject: [PATCH 1/4] [Net11] Fix for MAUIG2045 false-positive warning on unsealed RelativeSource AncestorType bindings (#36905) > [!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! ### Root Cause The issue occurs because of a change that taught the XAML source generator to compile RelativeSource AncestorType bindings at build time instead of always relying on reflection. This introduced a build warning (MAUIG2045) whenever a bound property could not be found on the declared AncestorType . This check is unsound because AncestorType matching in XAML is polymorphic: at runtime, the framework walks up the visual tree and accepts any ancestor whose type matches the declared type or a subclass of it. A property missing on the declared type (e.g., ContentPage ) may still be legitimately supplied by a derived class used at runtime (e.g., BasePage : ContentPage declaring SelectedItem ). Since the generator checked only the declared type, it produced false positive warnings that broke builds using TreatWarningsAsErrors=true . ### Description of Change The fix narrows the diagnostic condition so MAUIG2045 fires only when the declared AncestorType is sealed . A sealed type has no subclasses, so a missing property there provably breaks the binding. For non-sealed types, the compiler cannot rule out a derived ancestor supplying the property, so the diagnostic is suppressed and the binding falls back to reflection at runtime, the same safe fallback already used for x:Reference bindings. This is a minimal, one-line change to the diagnostic condition. It was validated with a regression test reproducing the exact scenario (an unsealed base page whose subclass supplies the bound property), confirming the test fails without the fix and passes with it, while the rest of the test suite is unaffected. ### Regression PR PR https://github.com/dotnet/maui/pull/34408 Tested the behavior in the following platforms. - [x] Android - [x] Mac - [x] iOS - [x] Windows ### Issues Fixed Fixes https://github.com/dotnet/maui/issues/36818 ### Output |Before Fix|After Fix| |--|--|