Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[XC] Fallback to reflection-based bindings for bindings with "invalid" path #24238

Conversation

simonrozsival
Copy link
Member

@simonrozsival simonrozsival commented Aug 14, 2024

Description of Change

We've improved binding optimizations in .NET 9 and it is now possible to compile all sorts of bindings that weren't supported in .NET 8 and earlier. This change can break existing code though:

  • In the cases when there is a binding with a Source but it inherits the x:DataType from the parent, there can often be a mismatch between the x:DataType and the type of the Source
  • Sometimes customers want to reference another element and access its BindingContext ({Binding BindingContext.Title Source={x:Reference ...}}). Since we don't support casting in the path, XamlC won't be able to correctly resolve and build the property chain (in the example BindingContext is of type object and it doesn't have any property Title).

While there are workarounds to these issues, it might be better to just fallback to a reflection-based binding that will resolve the actual properties at runtime in these cases to keep the apps working and produce a warning so that the developer can either choose to ignore it or address it. Feedback is very welcome.

I recommend hiding whitespace changes when looking at the code diff.

Issues Fixed

Fixes #23711

@simonrozsival simonrozsival marked this pull request as ready for review August 19, 2024 09:38
@simonrozsival simonrozsival requested a review from a team as a code owner August 19, 2024 09:38
Copy link
Member

@rmarinho rmarinho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/AutomationProperties.xaml(9,4): XamlC warning XC0618: Property, Property setter or BindableProperty "Name" is deprecated. [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/AutomationProperties.xaml(10,4): XamlC warning XC0618: Property, Property setter or BindableProperty "HelpText" is deprecated. [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/AutomationProperties.xaml(12,4): XamlC warning XC0618: Property, Property setter or BindableProperty "LabeledBy" is deprecated. [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Issues/Maui17484.xaml(10,17): XamlC warning XC0618: Property, Property setter or BindableProperty "Name" is deprecated. [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/WarnOnObsolete.xaml(6,25): XamlC warning XC0618: Property, Property setter or BindableProperty "ObsoleteBP" is deprecated. [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/WarnOnObsolete.xaml(6,42): XamlC warning XC0618: Property, Property setter or BindableProperty "ObsoleteProp" is deprecated. [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/WarnOnObsolete.xaml(6,61): XamlC warning XC0618: Property, Property setter or BindableProperty "ObsoletePropSetter" is deprecated. [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/BindingsCompiler.xaml(28,20): XamlC error XC0045: Binding: Property "GlobalText" not found on "System.Object". [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/BindingsCompiler.xaml : XamlC error : Index (zero based) must be greater than or equal to zero and less than the size of the argument list. [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Issues/Gh2517.xaml(6,12): XamlC error XC0045: Binding: Property "MissingProperty" not found on "Microsoft.Maui.Controls.Label". [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Issues/Gh2517.xaml : XamlC error : Index (zero based) must be greater than or equal to zero and less than the size of the argument list. [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Issues/Gh3606.xaml(4,16): XamlC error XC0045: Binding: Property "Content" not found on "System.String". [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Issues/Gh3606.xaml : XamlC error : Index (zero based) must be greater than or equal to zero and less than the size of the argument list. [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Issues/Maui20768.xaml(6,32): XamlC error XC0045: Binding: Property "Title" not found on "Microsoft.Maui.Controls.Xaml.UnitTests.ViewModel20768". [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Issues/Maui20768.xaml : XamlC error : Index (zero based) must be greater than or equal to zero and less than the size of the argument list. [/Users/builder/azdo/_work/2/s/src/Controls/tests/Xaml.UnitTests/Controls.Xaml.UnitTests.csproj]
    7 Warning(s)
    8 Error(s)

@rmarinho
Copy link
Member

/rebase

@github-actions github-actions bot force-pushed the fallback-for-bindings-with-non-compilable-path branch from c42cefe to 7a819a3 Compare August 24, 2024 22:58
@PureWeen PureWeen dismissed rmarinho’s stale review August 27, 2024 14:37

Errors have been fixed

@PureWeen PureWeen merged commit e2427df into dotnet:net9.0 Aug 27, 2024
117 checks passed
@samhouts samhouts added the fixed-in-net9.0-nightly This may be available in a nightly release! label Aug 27, 2024
@samhouts samhouts added fixed-in-9.0.0-rc.2.24503.2 and removed fixed-in-net9.0-nightly This may be available in a nightly release! labels Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants