unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.89k stars 720 forks source link

System.Exception when referencing ItemsRepeater inside of UserControl #4610

Closed s-beltz closed 3 years ago

s-beltz commented 3 years ago

Current behavior

When using ItemsRepeater inside UserControl System.Exception is thrown upon loading the UserControl.

Expected behavior

ItemsRepeater is loaded and displayed correctly.

Exception Stack

System.Exception: 'Failed to load ApliconusUnoDemoApp.MainPage: System.TypeLoadException: Could not load type of field 'Apliconus.CompositeViews.Portfolio.PortfolioView:_component_0' (2) due to: Could not resolve type with token 01000023 from typeref (expected class 'Microsoft.UI.Xaml.Controls.ItemsRepeater' in assembly 'Uno.UI, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null') assembly:Uno.UI, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null type:Microsoft.UI.Xaml.Controls.ItemsRepeater member:(null) at ApliconusUnoDemoApp.MainPage..ctor () [0x000df] in C:\VSO2.1\5-Apps\APLICONUS Foundation 5.1\Demos\ApliconusUnoDemoApp\ApliconusUnoDemoApp.Shared\MainPage.xaml.cs:111 at ApliconusUnoDemoApp.Droid.MetadataBuilder_890.CreateInstance () [0x00000] in C:\VSO2.1\5-Apps\APLICONUS Foundation 5.1\Demos\ApliconusUnoDemoApp\ApliconusUnoDemoApp.Droid\obj\Debug\100\g\BindableTypeProvidersSourceGenerator\BindableMetadata.g.cs:36320 at Windows.UI.Xaml.Controls.Frame.CreatePageInstance (System.Type sourcePageType) [0x00016] in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:416 at Windows.UI.Xaml.PagePool.DequeuePage (System.Type pageType) [0x00007] in C:\a\1\s\src\Uno.UI\UI\Xaml\PagePool.cs:69 at Windows.UI.Xaml.Controls.Frame.CreatePageInstanceCached (System.Type sourcePageType) [0x00000] in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:406 at Windows.UI.Xaml.Controls.Frame.InnerNavigate (Windows.UI.Xaml.Navigation.PageStackEntry entry, Windows.UI.Xaml.Navigation.NavigationMode mode) [0x000a1] in C:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:313 '

How to reproduce it (as minimally and precisely as possible)

This UserControl in a blank Uno app produces the mentioned exception

<UserControl x:Class="Apliconus.CompositeViews.Portfolio.PortfolioView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="using:Apliconus.CompositeViews.Portfolio"
             xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
             xmlns:contracts="using:Apliconus.CompositeViews.Contracts.Portfolio"
             d:DesignHeight="300"
             d:DesignWidth="400"
             xmlns:android="http://uno.ui/android"
             xmlns:ios="http://uno.ui/ios"
             xmlns:wasm="http://uno.ui/wasm"
             xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:not_win="http://uno.ui/not_win"
             xmlns:not_android="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d android ios wasm not_win">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <local:PortfolioSectionLayout x:Key="PortfolioSectionLayout" />
                    <local:PortfolioItemLayout x:Key="PortfolioItemLayout" />
                </ResourceDictionary>
                <ResourceDictionary>
                    <DataTemplate x:DataType="contracts:IPortfolioItem"
                                  x:Key="PortfolioItemTemplate">
                        <local:PortfolioViewItem Title="{x:Bind Path=Title, Mode=OneWay}" />
                    </DataTemplate>
                    <DataTemplate x:DataType="contracts:PortfolioSection"
                                  x:Key="PortfolioItemGroupTemplate">
                        <Border CornerRadius="20,0,0,0"
                                Background="AliceBlue"
                                BorderBrush="Blue">
                            <Grid Margin="20,20,0,0">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="40" />
                                    <RowDefinition Height="*" />
                                </Grid.RowDefinitions>
                                <Rectangle Fill="LightSkyBlue" />
                                <TextBlock Text="{x:Bind Path=Title, Mode=OneWay}"
                                           VerticalAlignment="Center"
                                           Margin="10,0" />
                                <muxc:ItemsRepeater Grid.Row="1"
                                                    Layout="{StaticResource PortfolioItemLayout}"
                                                    ItemTemplate="{StaticResource PortfolioItemTemplate}"
                                                    ItemsSource="{x:Bind Items, Mode=OneWay}" />
                            </Grid>
                        </Border>
                    </DataTemplate>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid>
        <ScrollViewer IsVerticalScrollChainingEnabled="False"
                      Padding="10">
            <muxc:ItemsRepeater x:Name="repeater"
                                Layout="{StaticResource PortfolioSectionLayout}"
                                ItemTemplate="{StaticResource PortfolioItemGroupTemplate}"
                                ItemsSource="{x:Bind PortfolioItemGroups, Mode=OneWay}"
                                HorizontalAlignment="Stretch" />
        </ScrollViewer>
    </Grid>
</UserControl>

Workaround

Environment

Nuget Package:

Nuget Package Version(s):

Affected platform(s):

  • [x] iOS
  • [x] Android
  • [ ] WebAssembly
  • [ ] WebAssembly renderers for Xamarin.Forms
  • [ ] macOS
  • [ ] Skia
    • [ ] WPF
    • [ ] GTK (Linux)
    • [ ] Tizen
  • [ ] Windows
  • [ ] Build tasks
  • [ ] Solution Templates

IDE:

  • [ ] Visual Studio 2017 (version: )
  • [x] Visual Studio 2019 (version: 16.7.7)
  • [ ] Visual Studio for Mac (version: )
  • [ ] Rider Windows (version: )
  • [ ] Rider macOS (version: )
  • [ ] Visual Studio Code (version: )

Relevant plugins:

  • [ ] Resharper (version: )

Anything else we need to know?

jeromelaban commented 3 years ago

Thank you for the report!

Could you attach a sample solution reproducing the issue ?

s-beltz commented 3 years ago

Thank you for the report!

Could you attach a sample solution reproducing the issue ?

Hi @jeromelaban, when building the minimal repro we found out that we have an issue in our library layout possibly related to MSBuild.Sdk.Extras version. The minimal repro works as expected except for a minor layout issue in Android that is not relevant to us at the moment. Sorry for not checking in advance, closing this issue for now.

Juriyx commented 2 years ago

@s-beltz so what exactly was the issue?

Juriyx commented 2 years ago

We have System.TypeLoadException: 'Could not resolve type with token 0100002e from typeref (expected class 'Windows.UI.Core.UIAsyncOperation' in assembly 'Uno, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null')' on .NET 6

s-beltz commented 2 years ago

Hello @Juriyx, as far as I can remember, this issue was related to the combination of multi platform builds with MSBuild.Sdk.Extras and custom controls. Our problem went away with an update of MSBuild.Sdk.Extras at the time. Unfortunately, this seems not to be related to your issue.

jeromelaban commented 2 years ago

We have System.TypeLoadException: 'Could not resolve type with token 0100002e from typeref (expected class 'Windows.UI.Core.UIAsyncOperation' in assembly 'Uno, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null')' on .NET 6

You're likely having an issue with an Uno 3.x and Uno 4.x combination, most likely because of a library you're referencing that has not been updated to Uno 4. It'd be best to open a discussion if this is not the case.