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

XamlC error XFC0045 with maui dotnet 9 preview 3 #22318

Open
rogerbriggen opened this issue May 9, 2024 · 15 comments
Open

XamlC error XFC0045 with maui dotnet 9 preview 3 #22318

rogerbriggen opened this issue May 9, 2024 · 15 comments
Assignees
Labels
area-xaml XAML, CSS, Triggers, Behaviors i/regression This issue described a confirmed regression on a currently supported version platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working

Comments

@rogerbriggen
Copy link

Description

If you use compiled bindings and you use x:Reference Bindings they don't work with dotnet 9 preview 3. It works fine with dotnet 9 preview 2 and dotnet 8.

Steps to Reproduce

  1. Clone the repo
  2. Install dotnet 9 preview 3
  3. dotnet workload restore
  4. dotnet build -> you will get the error

Link to public reproduction project repository

https://github.com/rogerbriggen/mauidotnet9pre3_collectionview

Version with bug

9.0.0-preview.3.10457

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

9.0.0-preview.2.10293

Affected platforms

Android, Windows

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

C:\temp\mauidotnet9pre3_collectionview-master>dotnet build
Wiederherstellung abgeschlossen (2.0s)
Sie verwenden eine Vorschauversion von .NET. Weitere Informationen: https://aka.ms/dotnet-support-policy
  mauidotnet9pre3_collectionview net9.0-windows10.0.19041.0 failed with 1 error(s) (9.7s)
    MainPage.xaml(16,17): XamlC error XFC0045: Binding: Property "SelectedItem" not found on "mauidotnet9pre3_collectionview.MainPageViewModel".
  mauidotnet9pre3_collectionview net9.0-android failed with 1 error(s) (13.1s)
    MainPage.xaml(16,17): XamlC error XFC0045: Binding: Property "SelectedItem" not found on "mauidotnet9pre3_collectionview.MainPageViewModel".

Erstellen von failed with 2 error(s) in 15.4s
@rogerbriggen rogerbriggen added the t/bug Something isn't working label May 9, 2024
Copy link
Contributor

github-actions bot commented May 9, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@rogerbriggen
Copy link
Author

The same error if you use
SelectionChangedCommandParameter="{Binding Source={RelativeSource Self}, Path=SelectedItem}"

@PureWeen PureWeen added the potential-regression This issue described a possible regression on a currently supported version., verification pending label May 10, 2024
@PureWeen PureWeen added this to the .NET 9 Planning milestone May 10, 2024
@kevinxufei kevinxufei added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed and removed potential-regression This issue described a possible regression on a currently supported version., verification pending labels May 11, 2024
@kevinxufei
Copy link
Collaborator

kevinxufei commented May 11, 2024

Verified this issue with Visual Studio 17.10 Preview 7.0 + NET9.0 SDK (9.0.100-preview.3.24204.13).
MauiVersion = 9.0.0-preview.3.10457, repro this issue;
MauiVersion = 9.0.0-preview.2.10293, works well.

@kevinxufei kevinxufei added potential-regression This issue described a possible regression on a currently supported version., verification pending i/regression This issue described a confirmed regression on a currently supported version and removed potential-regression This issue described a possible regression on a currently supported version., verification pending labels May 11, 2024
@Eilon Eilon added the area-xaml XAML, CSS, Triggers, Behaviors label May 11, 2024
@cgp1976
Copy link

cgp1976 commented May 13, 2024

Hi guys, I am facing these issues as well. Is there any workaround settings where we can bypass the error from XamlC

similar to
<XFDisableTargetsValidation>True</XFDisableTargetsValidation>

cos right now, I can't build and compile the project. kindly advise.

@drasticactions
Copy link
Contributor

public static BuildExceptionCode BindingPropertyNotFound = new BuildExceptionCode("XFC", 0045, nameof(BindingPropertyNotFound), "");

<Item ItemId=";BindingPropertyNotFound" ItemType="0;.resx" PsrId="211" InstFlg="true" Leaf="true">
<Str Cat="Text">
<Val><![CDATA[Binding: Property "{0}" not found on "{1}".]]></Val>
</Str>
<Disp Icon="Str" />
<Cmts>
<Cmt Name="Dev"><![CDATA[0 is property name, 1 is type name]]></Cmt>
</Cmts>
</Item>

There's been a few changes in SetPropertiesVisitor since Preview2, and I think this is the only place that throws that exception: https://github.com/dotnet/maui/blame/main/src/Controls/src/Build.Tasks/SetPropertiesVisitor.cs

@simonrozsival Would you have any ideas what it could be?

@simonrozsival
Copy link
Member

@rogerbriggen @drasticactions previously, any binding with Source wasn't compiled. After a recent change (#20610), we can now compile all bindings. Unfortunately, we can't infer the x:DataType form Source yet (#21834) and so in this case, the compiler doesn't know that it shouldn't be looking for the property SelectedItem on MainPageViewModel but instead on CollectionView.

As a fix, you can set the x:DataType on the binding that shouldn't inherit the parent's x:DataType:

<CollectionView 
    x:Name="myCollection" 
    ItemsSource="{Binding Items}" 
    ...
    SelectionChangedCommandParameter="{Binding Source={x:Reference myCollection}, Path=SelectedItem, x:DataType=CollectionView}">
    <CollectionView.ItemTemplate>
     ...
    </CollectionView.ItemTemplate>
</CollectionView>

Does this solve your problem?

@cgp1976
Copy link

cgp1976 commented May 13, 2024

one thing I found out is that when any parent element has assigned the x Attribute x:DataType with value, those child elements will be overriding with the parent value... basically, it is using the parent context to find the binding hence it throws the Property Binding not found.

@cgp1976
Copy link

cgp1976 commented May 13, 2024

@rogerbriggen @drasticactions previously, any binding with Source wasn't compiled. After a recent change (#20610), we can now compile all bindings. Unfortunately, we can't infer the x:DataType form Source yet (#21834) and so in this case, the compiler doesn't know that it shouldn't be looking for the property SelectedItem on MainPageViewModel but instead on CollectionView.

As a fix, you can set the x:DataType on the binding that shouldn't inherit the parent's x:DataType:

<CollectionView 
    x:Name="myCollection" 
    ItemsSource="{Binding Items}" 
    ...
    SelectionChangedCommandParameter="{Binding Source={x:Reference myCollection}, Path=SelectedItem, x:DataType=CollectionView}">
    <CollectionView.ItemTemplate>
     ...
    </CollectionView.ItemTemplate>
</CollectionView>

Does this solve your problem?
Many thanks for the response. Seem like I just need to remove the x:DataType for the time being.

@drasticactions
Copy link
Contributor

@simonrozsival Okay, that makes sense. Should this issue be closed then and duplicated under #21834?

@simonrozsival
Copy link
Member

@drasticactions I'm not sure. I think this is mostly a documentation issue. We've made changes to how XamlC compiles bindings in .NET 9, but we haven't updated the docs yet. I think we need a new issue that will track the necessary changes to documentation and then we can close this issue.

@rogerbriggen
Copy link
Author

rogerbriggen commented May 13, 2024

@rogerbriggen @drasticactions previously, any binding with Source wasn't compiled. After a recent change (#20610), we can now compile all bindings. Unfortunately, we can't infer the x:DataType form Source yet (#21834) and so in this case, the compiler doesn't know that it shouldn't be looking for the property SelectedItem on MainPageViewModel but instead on CollectionView.

As a fix, you can set the x:DataType on the binding that shouldn't inherit the parent's x:DataType:

<CollectionView 
    x:Name="myCollection" 
    ItemsSource="{Binding Items}" 
    ...
    SelectionChangedCommandParameter="{Binding Source={x:Reference myCollection}, Path=SelectedItem, x:DataType=CollectionView}">
    <CollectionView.ItemTemplate>
     ...
    </CollectionView.ItemTemplate>
</CollectionView>

Does this solve your problem?

@cgp1976 Yes, this solves this issue. The only thing which is, that Visual Studio shows an error
image
The text means "the datatype property was not found in type BindingExtension.
Do I need to create a bug for that? Where?

@simonrozsival
Copy link
Member

simonrozsival commented May 13, 2024

@rogerbriggen I think this is the same warning we saw in #21434. This seems to be a bug in the XAML editor in VS. I wonder where the best place to report it is (cc @StephaneDelcroix @PureWeen).

@drasticactions
Copy link
Contributor

@mgoertz-msft Would you know?

@mgoertz-msft
Copy link
Contributor

Xamarin and MAUI never cease to surprise me on what they allow that other platforms like WPF and UWP/WinUI don't. I had no idea this was allowed to be used that way.

@simonrozsival
Copy link
Member

I reported the issue in the VS Code extension here: microsoft/vscode-dotnettools#1131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-xaml XAML, CSS, Triggers, Behaviors i/regression This issue described a confirmed regression on a currently supported version platform/android 🤖 platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Status: Todo
Development

No branches or pull requests

10 participants