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 Compilation errors when upgrading to Microsoft.Maui.Controls 8.0.20 #21757

Closed
konradzuse opened this issue Apr 10, 2024 · 23 comments · Fixed by #23043
Closed

XamlC Compilation errors when upgrading to Microsoft.Maui.Controls 8.0.20 #21757

konradzuse opened this issue Apr 10, 2024 · 23 comments · Fixed by #23043
Assignees
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.21 fixed-in-8.0.70 fixed-in-9.0.0-preview.5.24307.10 fixed-in-9.0.0-preview.6.24327.7 i/regression This issue described a confirmed regression on a currently supported version p/0 Work that we can't release without platform/android 🤖 platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@konradzuse
Copy link

Description

Update the Nuget packages and compile the app, various compilation errors are reported for things like this...

<Style x:Key="Separator" TargetType="{x:Type BoxView}">
        <Setter Property="Color" Value="{StaticResource Gray-200}"/>
        <Setter Property="HeightRequest" Value="1"/>
        <Setter Property="Margin" Value="0,6"/>
        <Setter Property="HorizontalOptions" Value="FillAndExpand"/>
    </Style>

Error XFC0040 XamlC: Cannot convert value "Color" to "Microsoft.Maui.Controls.BindableProperty"

Other xaml files get comilation error..

Error XamlC: Input string was not in a correct format. Failure to parse near offset 69. Unexpected closing brace without a corresponding opening brace.

Despite them being perfectly valid Xaml and compiling correctly with 8.0.14

Steps to Reproduce

  1. Update Nuget packages to 8.0.20
  2. Compile app (Android/iOS)

Link to public reproduction project repository

No response

Version with bug

8.0.20 SR4

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

8.0.14 SR3.1

Affected platforms

iOS, Android

Affected platform versions

No response

Did you find any workaround?

No, removing the code presented as errors results in a new error reported in another file that was previously not reported.

Relevant log output

No response

@konradzuse konradzuse added the t/bug Something isn't working label Apr 10, 2024
@PureWeen PureWeen added i/regression This issue described a confirmed regression on a currently supported version potential-regression This issue described a possible regression on a currently supported version., verification pending and removed i/regression This issue described a confirmed regression on a currently supported version labels Apr 10, 2024
@PureWeen PureWeen added this to the .NET 8 SR4 milestone Apr 10, 2024
@jonathanpeppers
Copy link
Member

@konradzuse what is the code at offset 69? Is it complaining about TargetType="{x:Type BoxView}" or {StaticResource Gray-200}?

The diff has changes to {x:Type}, but not really any parsing logic I can tell:

@konradzuse
Copy link
Author

@konradzuse what is the code at offset 69? Is it complaining about TargetType="{x:Type BoxView}" or {StaticResource Gray-200}?

There are 2 errors, one about my style binding to the BoxView Color property, and multiple others about closing braces at offset 69. Oddly every file it complains about is offset 69, and there's nothing to note at that offset.

@jonathanpeppers
Copy link
Member

We think something went wrong here:

So, a workaround should be to use TargetType="BoxView" -- just removing the {x:Type} markup extension.

@simonrozsival simonrozsival self-assigned this Apr 10, 2024
@ninachen03 ninachen03 added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Apr 11, 2024
@ninachen03
Copy link

Verified this issue with Visual Studio 17.10.0 Preview 3(8.0.20). Can repro it but not repro in Maui control version:8.0.14

@konradzuse
Copy link
Author

I can confirm removing {x:Type} resolves the issues in both styles and xaml Content pages.

@egvijayanand
Copy link
Contributor

egvijayanand commented Apr 12, 2024

Facing this issue in .NET 9 Preview 3 as well while using {x:Type} with DataTemplate.

Replacing {x:Type} with just its value resolves it for the time being.

@TomSoPolaris
Copy link

TomSoPolaris commented Apr 12, 2024

I get the same "Failure to parse near offset 69" error for DataTemplates that are inside a ContentPage ResourceDictionary that use x:Type

Something like:

<ContentPage.Resources>
        <ResourceDictionary>
            <DataTemplate x:Key="myTemplate" x:DataType="{x:Type myNamespace:someModel}">

The proposed workarounds don't resolve the issues in this case

@TomSoPolaris
Copy link

I take it back! The workaround does work. I had multiple DataTemplates on the same page.

Updated code:

<ContentPage.Resources>
        <ResourceDictionary>
            <DataTemplate x:Key="myTemplate" x:DataType="myNamespace:someModel">

@PureWeen
Copy link
Member

This fix should be available on our nightly feed if you use

8.0.21-preview.10505

https://github.com/dotnet/maui/wiki/Nightly-Builds

@Delphinidae84
Copy link

Delphinidae84 commented May 8, 2024

This fix should be available on our nightly feed if you use

8.0.21-preview.10505

https://github.com/dotnet/maui/wiki/Nightly-Builds

Unfortunately this issue still persists in the current 8.0.21 see here.

In our case it even occurs in a simple case like:

<Setter Property="TextDecorations" Value="Strikethrough" />

Error XFC0040 Cannot convert value "TextDecorations" to "Microsoft.Maui.Controls.BindableProperty".

@RobTF
Copy link

RobTF commented May 20, 2024

As of 8.0.40 I'm still getting the problem. 8.0.14 works fine.

@Haukinger
Copy link

Haukinger commented May 27, 2024

8.0.40 here, works with regular types ({x:Type someNamespace:SomeType}), at least with DataTemplate x:DataType (I'm unsure of Style TargetType and DataTrigger TargetType),

but not with nested types ({x:Type someNamespace:IAnInterface+ReturnType}).

@cat0363
Copy link
Contributor

cat0363 commented Jun 7, 2024

I'm also having this issue with version 8.0.40.

@simonrozsival
Copy link
Member

@RobTF @cat0363 could you please share an example of your failing XAML? I can't reproduce this problem with 8.0.40 anymore.

@StephaneDelcroix does x:Type support nested types? (cc @Haukinger)

@cat0363
Copy link
Contributor

cat0363 commented Jun 10, 2024

@simonrozsival , Below is an example where the problem occurred.

<Grid IsVisible="True">
    <DataTrigger TargetType="{x:Type Grid}" Binding="{Binding TestValue}" Value="1">
        <Setter Property="IsVisible" Value="False" />
    </DataTrigger>
</Grid>

When I changed the way to write TargetType of DataTrigger as shown below, the build error was resolved.

<Grid IsVisible="True">
    <DataTrigger TargetType="Grid" Binding="{Binding TestValue}" Value="1">
        <Setter Property="IsVisible" Value="False" />
    </DataTrigger>
</Grid>

@simonrozsival
Copy link
Member

@cat0363 I'm only getting MainPage.xaml(36,18): XamlC error XFC0009: No property, BindableProperty, or event found for "Children", or mismatching type between value and property. which is caused by missing <Grid.DataTriggers>, this fixed snippet works correctly:

<Grid IsVisible="True">
    <Grid.Triggers>
        <DataTrigger TargetType="{x:Type Grid}" Binding="{Binding TestValue}" Value="1">
            <Setter Property="IsVisible" Value="False"/>
        </DataTrigger>
    </Grid.Triggers>
</Grid>

@cat0363
Copy link
Contributor

cat0363 commented Jun 11, 2024

@simonrozsival , Sorry, I made a typo. <Grid.Triggers></Grid.Triggers> was missing when posting.

    <Grid IsVisible="True">
        <Grid.Triggers>
            <DataTrigger TargetType="{x:Type Grid}" Binding="{Binding TestValue}" Value="1">
                <Setter Property="IsVisible" Value="False" />
            </DataTrigger>
         </Grid.Triggers>
    </Grid>

It might be because I didn't clean the app when it was built.
Maybe there was some garbage left over from the previous version.
The build now works. Thank you for your comment.

@cat0363
Copy link
Contributor

cat0363 commented Jun 11, 2024

@simonrozsival , I found a condition that causes a build error.
An error occurs with the TargetType of DataTrigger, but it was a case where the DataTrigger existed inside the DataTemplate.

[MainPage.xaml]

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:DataTrigerTest"
             x:Class="DataTrigerTest.MainPage" x:DataType="local:ViewModelMainPage">

    <StackLayout Orientation="Vertical" BindableLayout.ItemsSource="{Binding TestList}" Spacing="5">
        <BindableLayout.ItemTemplate>
            <DataTemplate x:DataType="{x:Type local:ViewModelTest}">
                <Grid BackgroundColor="Blue" HeightRequest="30">
                    <Grid.Triggers>
                        <DataTrigger TargetType="{x:Type Grid}" Binding="{Binding TestValue}" Value="0">
                            <Setter Property="BackgroundColor" Value="Red" />
                        </DataTrigger>
                    </Grid.Triggers>
                </Grid>
            </DataTemplate>
        </BindableLayout.ItemTemplate>
    </StackLayout>

</ContentPage>

By changing the TargetType of the above DataTrigger from {x:Type Grid} to Grid, the build will pass.

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:DataTrigerTest"
             x:Class="DataTrigerTest.MainPage" x:DataType="local:ViewModelMainPage">

    <StackLayout Orientation="Vertical" BindableLayout.ItemsSource="{Binding TestList}" Spacing="5">
        <BindableLayout.ItemTemplate>
            <DataTemplate x:DataType="{x:Type local:ViewModelTest}">
                <Grid BackgroundColor="Blue" HeightRequest="30">
                    <Grid.Triggers>
                        <DataTrigger TargetType="Grid" Binding="{Binding TestValue}" Value="0">
                            <Setter Property="BackgroundColor" Value="Red" />
                        </DataTrigger>
                    </Grid.Triggers>
                </Grid>
            </DataTemplate>
        </BindableLayout.ItemTemplate>
    </StackLayout>

</ContentPage>

The code for MainPage.xaml.cs is shown below.

[MainPage.xaml.cs]

    public partial class MainPage : ContentPage
    {
        private ViewModelMainPage pVmTest = new ViewModelMainPage();

        public MainPage()        
        {
            InitializeComponent();
            this.BindingContext = pVmTest;
        }
    }

    public class ViewModelMainPage
    {
        public List<ViewModelTest> TestList { get; set; }

        public ViewModelMainPage()
        {
            TestList = new List<ViewModelTest>()
            {
                new ViewModelTest() { TestValue = 0 },
                new ViewModelTest() { TestValue = 1 },
                new ViewModelTest() { TestValue = 2 },
                new ViewModelTest() { TestValue = 3 }
            };
        }
    }

    public class ViewModelTest
    {
        public int TestValue { get; set; }
    }

When I investigated the location where the build error occurred, I found that it was when there was a DataTrigger in the DataTemplate as shown above.

@simonrozsival
Copy link
Member

@cat0363 can you also please share the error message you're getting?

@cat0363
Copy link
Contributor

cat0363 commented Jun 11, 2024

@simonrozsival , Thank you for your reply.
Below is the error message I got.

MainPage.xaml(13,37): XamlC error XFC0040: Cannot convert value "BackgroundColor" to "Microsoft.Maui.Controls.BindableProperty".

@simonrozsival
Copy link
Member

@cat0363 thanks for the repro, I opened a bugfix PR: #23043

@cat0363
Copy link
Contributor

cat0363 commented Jun 13, 2024

@simonrozsival , thank you for opening a PR for the bug fix.

@samhouts samhouts added fixed-in-9.0.0-preview.5.24307.10 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 fixed-in-8.0.40 labels Jul 1, 2024
@rodrigobarbosa1406
Copy link

I take it back! The workaround does work. I had multiple DataTemplates on the same page.

Updated code:

<ContentPage.Resources>
        <ResourceDictionary>
            <DataTemplate x:Key="myTemplate" x:DataType="myNamespace:someModel">

This answer helped me.

I changed this code...
<DataTemplate x:DataType="{x:Type dataTransferObjectsAddress:DistrictGetDTO}">

...for this:
<DataTemplate x:DataType="dataTransferObjectsAddress:DistrictGetDTO">

Thank you very much @TomSoPolaris !

@github-actions github-actions bot locked and limited conversation to collaborators Aug 30, 2024
@samhouts samhouts added the area-xaml XAML, CSS, Triggers, Behaviors label Sep 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-xaml XAML, CSS, Triggers, Behaviors fixed-in-8.0.21 fixed-in-8.0.70 fixed-in-9.0.0-preview.5.24307.10 fixed-in-9.0.0-preview.6.24327.7 i/regression This issue described a confirmed regression on a currently supported version p/0 Work that we can't release without platform/android 🤖 platform/iOS 🍎 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.