Skip to content

Exception on Android and WASM after adding a style to a menuflyoutitem #3216

Closed

Description

@BrianDT

Current behavior

Exception generated on execution when loading a page that contains

                <AppBarButton.Flyout>
                    <MenuFlyout>
                        <MenuFlyoutItem Text="Tutorial"
                                        Style="{StaticResource menuFlyoutItemStyle}"/>
                    </MenuFlyout>
                </AppBarButton.Flyout>

Expected behavior

No exception should be thrown as on UWP

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

Example that reproduces the issue is available on
https://github.com/BrianDT/UnoFlyoutStyleIssue

Environment

Nuget Package: Uno.UI

Package Version(s): 2.4.0 and 3.0.0-dev.76

Affected platform(s):

  • iOS
  • Android
  • WebAssembly
  • WebAssembly renderers for Xamarin.Forms
  • macOS
  • Windows
  • Build tasks
  • Solution Templates

Visual Studio:

  • 2017 (version: )
  • 2019 (version: )
  • for Mac (version: )

Relevant plugins:

  • Resharper (version: )

Anything else we need to know?

Activity

  1. added
    kind/bug
    triage/untriaged
    on May 21, 2020
  2. BrianDT commented on May 21, 2020

    @BrianDT
    Author

    System.Exception
    Message=Failed to load UnoFlyoutStyleIssue.MainPage: System.InvalidOperationException: The resource menuFlyoutItemStyle cannot be found
    at UnoFlyoutStyleIssue.MainPage+<>c__DisplayClass2_0.b__1 (UnoFlyoutStyleIssue.MainPage c3) [0x00001] in D:\Development\GitHub\UnoFlyoutStyleIssue\UnoFlyoutStyleIssue\UnoFlyoutStyleIssue.Droid\obj\Debug\90\g\XamlCodeGenerator\MainPage_523c63a278830d164cac6f1cfbdba873.g.cs:87
    at Uno.Extensions.ObjectExtensions.Apply[TSource] (TSource source, System.Action`1[T] action) [0x00000] in D:\a\1\s\src\Uno.Core\Extensions\ObjectExtensions.cs:110
    at UnoFlyoutStyleIssue.MainPage.InitializeComponent () [0x000bc] in D:\Development\GitHub\UnoFlyoutStyleIssue\UnoFlyoutStyleIssue\UnoFlyoutStyleIssue.Droid\obj\Debug\90\g\XamlCodeGenerator\MainPage_523c63a278830d164cac6f1cfbdba873.g.cs:81
    at UnoFlyoutStyleIssue.MainPage..ctor () [0x00013] in D:\Development\GitHub\UnoFlyoutStyleIssue\UnoFlyoutStyleIssue\UnoFlyoutStyleIssue.Shared\MainPage.xaml.cs:27
    at UnoFlyoutStyleIssue.Droid.MetadataBuilder_643.CreateInstance () [0x00000] in D:\Development\GitHub\UnoFlyoutStyleIssue\UnoFlyoutStyleIssue\UnoFlyoutStyleIssue.Droid\obj\Debug\90\g\BindableTypeProvidersSourceGenerator\BindableMetadata.g.cs:31058
    at Windows.UI.Xaml.Controls.Frame.CreatePageInstance (System.Type sourcePageType) [0x00016] in d:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:414
    at Windows.UI.Xaml.PagePool.DequeuePage (System.Type pageType) [0x00007] in d:\a\1\s\src\Uno.UI\UI\Xaml\PagePool.cs:69
    at Windows.UI.Xaml.Controls.Frame.CreatePageInstanceCached (System.Type sourcePageType) [0x00000] in d:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:404
    at Windows.UI.Xaml.Controls.Frame.InnerNavigate (Windows.UI.Xaml.Navigation.PageStackEntry entry, Windows.UI.Xaml.Navigation.NavigationMode mode) [0x0009b] in d:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:311

  3. added
    platform/android 🤖
    area/code-generation
    platform/wasm 🌐
    and removed
    triage/untriaged
    on May 30, 2020
  4. Xiaoy312 commented on May 30, 2020

    @Xiaoy312
    Contributor

    strangely the generated local resource (style) isnt being used anywhere:

    private void InitializeComponent()
    {
        var nameScope = new global::Windows.UI.Xaml.NameScope();
        NameScope.SetNameScope(this, nameScope);
    
        Content = new global::Windows.UI.Xaml.Controls.Grid
        {
            RowDefinitions = { ... },
            Children =
            {
                new global::Windows.UI.Xaml.Controls.TextBlock { ... }.MainPage_dec80355600d10724bff248f43da21f1_XamlApply(...),
                new global::Windows.UI.Xaml.Controls.CommandBar
                {
                    // Empty collection
                    SecondaryCommands = 
                    {
                        new global::Windows.UI.Xaml.Controls.AppBarButton
                        {
                            ...,
                            Flyout = 								new global::Windows.UI.Xaml.Controls.MenuFlyout
                            {
                                // Source ..\..\..\..\..\..\..\UnoFlyoutStyleIssue.Shared\MainPage.xaml (Line 33:26)
                                Items = 
                                {
                                    new global::Windows.UI.Xaml.Controls.MenuFlyoutItem
                                    {
    -                                    Style = (Windows.UI.Xaml.Style)global::Windows.UI.Xaml.Markup.XamlBindingHelper.ConvertValue(typeof(Windows.UI.Xaml.Style), (global::Windows.UI.Xaml.Application.Current.Resources["menuFlyoutItemStyle"] ?? throw new InvalidOperationException("The resource menuFlyoutItemStyle cannot be found"))),
                                        ...
                                    }.MainPage_dec80355600d10724bff248f43da21f1_XamlApply(...),
                                }
                            },
                            // Source ..\..\..\..\..\..\..\UnoFlyoutStyleIssue.Shared\MainPage.xaml (Line 27:18)
                        }.MainPage_dec80355600d10724bff248f43da21f1_XamlApply(...),
                    },
                    // Source ..\..\..\..\..\..\..\UnoFlyoutStyleIssue.Shared\MainPage.xaml (Line 23:10)
                }.MainPage_dec80355600d10724bff248f43da21f1_XamlApply(...),
            }
        }.MainPage_dec80355600d10724bff248f43da21f1_XamlApply(...);
    
        this.Apply(...).Apply(...);
    
        OnInitializeCompleted();
        InitializeXamlOwner();
    
        // Source ..\..\..\..\..\..\..\UnoFlyoutStyleIssue.Shared\MainPage.xaml (Line 9:10)
    -    new global::Windows.UI.Xaml.Style(typeof(global::Windows.UI.Xaml.Controls.MenuFlyoutItem))
    -    {
    -        Setters = 
    -        {
    -            new global::Windows.UI.Xaml.Setter(global::Windows.UI.Xaml.Controls.MenuFlyoutItem.BackgroundProperty, () => (Windows.UI.Xaml.Media.Brush)(Windows.UI.Xaml.Media.Brush)global::Uno.UI.GlobalStaticResources.ApplicationPageBackgroundThemeBrush),
    -            new global::Windows.UI.Xaml.Setter(global::Windows.UI.Xaml.Controls.MenuFlyoutItem.ForegroundProperty, () => (Windows.UI.Xaml.Media.Brush)(Windows.UI.Xaml.Media.Brush)global::Uno.UI.GlobalStaticResources.ApplicationForegroundThemeBrush),
    -            new global::Windows.UI.Xaml.Setter(global::Windows.UI.Xaml.Controls.MenuFlyoutItem.OpacityProperty, (double)1d/* double/double, 1, Setter/Value */),
    -        }
    -    };
    }
  5. jeromelaban commented on May 31, 2020

    @jeromelaban
    Member

    Thanks for the report!

    Indeed, there's a special case for this, where you defined your style using x:Name instead of x:Key. This may be something that will be addressed by #1766.

    /cc @davidjohnoliver

  6. added
    project/styling 👔
    and removed
    platform/android 🤖
    project/styling 👔
    platform/wasm 🌐
    on May 31, 2020
  7. davidjohnoliver commented on Jun 1, 2020

    @davidjohnoliver
    Contributor

    Yes, this should be fixed with #1766.

  8. xperiandri commented on Jun 14, 2020

    @xperiandri
    Contributor

    Looks like it is related

    System.Exception: 'Failed to load Frebo.Biblioteko.Mobile.MainView.HomePage: System.MissingMethodException: Method not found: Windows.UI.Xaml.Media.SolidColorBrush Uno.UI.GlobalStaticResources.get_ApplicationForegroundThemeBrush()
      at Windows.UI.Xaml.Setter.ApplyTo (Windows.UI.Xaml.DependencyObject o) [0x00008] in D:\a\1\s\src\Uno.UI\UI\Xaml\Setter.cs:76 
      at Windows.UI.Xaml.Style.ApplyTo (Windows.UI.Xaml.DependencyObject o, Windows.UI.Xaml.DependencyPropertyValuePrecedences precedence) [0x0003f] in D:\a\1\s\src\Uno.UI\UI\Xaml\Style\Style.cs:68 
      at Windows.UI.Xaml.FrameworkElement.OnStyleChanged (Windows.UI.Xaml.Style oldStyle, Windows.UI.Xaml.Style newStyle, Windows.UI.Xaml.DependencyPropertyValuePrecedences precedence) [0x00011] in D:\a\1\s\src\Uno.UI\UI\Xaml\FrameworkElement.cs:374 
      at Windows.UI.Xaml.FrameworkElement.ApplyDefaultStyle () [0x0001c] in D:\a\1\s\src\Uno.UI\UI\Xaml\FrameworkElement.cs:392 
      at Windows.UI.Xaml.FrameworkElement.ApplyStyles () [0x00006] in D:\a\1\s\src\Uno.UI\UI\Xaml\FrameworkElement.cs:275 
      at Windows.UI.Xaml.FrameworkElement.CreationComplete () [0x00014] in D:\a\1\s\src\Uno.UI\UI\Xaml\FrameworkElement.cs:293 
      at Frebo.Biblioteko.Mobile.MainView.HomePage+<>c.<InitializeComponent>b__1_23 (Microsoft.Toolkit.Uwp.UI.Controls.ImageEx c11) [0x0000d] in C:\Users\Andrii\Dev\Frebo\Biblioteko\Biblioteko.Mobile.Android\obj\Debug\90\g\XamlCodeGenerator\HomePage_a1c3e85ce99589774302cf397f8d10aa.g.cs:479 
      at Frebo.Biblioteko.Mobile.HomePage_a1c3e85ce99589774302cf397f8d10aaXamlApplyExtensions.HomePage_a1c3e85ce99589774302cf397f8d10aa_XamlApply (Microsoft.Toolkit.Uwp.UI.Controls.ImageEx instance, Frebo.Biblioteko.Mobile.HomePage_a1c3e85ce99589774302cf397f8d10aaXamlApplyExtensions+XamlApplyHandler9 handler) [0x00001] in C:\Users\Andrii\Dev\Frebo\Biblioteko\Biblioteko.Mobile.Android\obj\Debug\90\g\XamlCodeGenerator\HomePage_a1c3e85ce99589774302cf397f8d10aa.g.cs:1146 
      at Frebo.Biblioteko.Mobile.MainView.HomePage.InitializeComponent () [0x00137] in C:\Users\Andrii\Dev\Frebo\Biblioteko\Biblioteko.Mobile.Android\obj\Debug\90\g\XamlCodeGenerator\HomePage_a1c3e85ce99589774302cf397f8d10aa.g.cs:164 
      at Frebo.Biblioteko.Mobile.MainView.HomePage..ctor () [0x00008] in C:\Users\Andrii\Dev\Frebo\Biblioteko\Biblioteko.Mobile.Shared\MainView\HomePage.xaml.cs:28 
      at Frebo.Biblioteko.Mobile.MetadataBuilder_766.CreateInstance () [0x00000] in C:\Users\Andrii\Dev\Frebo\Biblioteko\Biblioteko.Mobile.Android\obj\Debug\90\g\BindableTypeProvidersSourceGenerator\BindableMetadata.g.cs:36273 
      at Windows.UI.Xaml.Controls.Frame.CreatePageInstance (System.Type sourcePageType) [0x00016] in D:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:416 
      at Windows.UI.Xaml.PagePool.DequeuePage (System.Type pageType) [0x00007] in D:\a\1\s\src\Uno.UI\UI\Xaml\PagePool.cs:69 
      at Windows.UI.Xaml.Controls.Frame.CreatePageInstanceCached (System.Type sourcePageType) [0x00000] in D:\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) [0x0009b] in D:\a\1\s\src\Uno.UI\UI\Xaml\Controls\Frame\Frame.cs:313 '
    
  9. xperiandri commented on Jun 14, 2020

    @xperiandri
    Contributor
    <tc:ImageEx CornerRadius="8" Source="{Binding ImageUrl}" />`
    <tc:ImageEx
                    Grid.RowSpan="2"
                    Grid.ColumnSpan="2"
                    Width="65"
                    Height="65"
                    Margin="15"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    Background="{StaticResource OffWhiteBrush}"
                    CornerRadius="999"
                    PlaceholderSource="ms-appx:///Assets/oval.png"
                    PlaceholderStretch="UniformToFill"
                    Source="{Binding AvatarURL}" />
    <tc:ImageEx
                    Grid.RowSpan="2"
                    Width="65"
                    Height="65"
                    Margin="15"
                    HorizontalAlignment="Center"
                    VerticalAlignment="Center"
                    BorderBrush="#D4D1C2"
                    BorderThickness="1"
                    CornerRadius="999"
                    PlaceholderSource="ms-appx:///Assets/oval.png"
                    PlaceholderStretch="UniformToFill"
                    Source="{Binding ImageUrl}" />
  10. xperiandri commented on Jun 14, 2020

    @xperiandri
    Contributor

    Happen on Android for me

  11. xperiandri commented on Jun 14, 2020

    @xperiandri
    Contributor

    Do I need to create a separate issue for this?

  12. xperiandri commented on Jun 14, 2020

    @xperiandri
    Contributor

    Tried <Border x:Key="*Work Around Border for ImageEx ApplicationForegroundThemeBrush Issue" Background="{ThemeResource ApplicationForegroundThemeBrush}" />
    Got Java.Lang.NullPointerException: 'Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference'

  13. xperiandri commented on Jun 14, 2020

    @xperiandri
    Contributor
    internal static global::Windows.UI.Xaml.Controls.Border Entry2_1
    		{
    			get
    			{
    				if(!_Entry2_1Initialized)
    				{
    					__Entry2_1BackingField = 
    						new global::Windows.UI.Xaml.Controls.Border
    						{
    							IsParsing = true
    							,
    							// Source ..\..\..\..\..\..\..\Biblioteko.Mobile.Shared\Assets\Resources\Components.xaml (Line 9:6)
    						}
    						.Components_f75bd78bb9117596abbc09f0af500bb6_XamlApply((Components_f75bd78bb9117596abbc09f0af500bb6XamlApplyExtensions.XamlApplyHandler0)(c0 => 
    						{
    							global::Uno.UI.ResourceResolver.ApplyResource(c0, global::Windows.UI.Xaml.Controls.Border.BackgroundProperty, "ApplicationForegroundThemeBrush", isThemeResourceExtension: true, context: global::Frebo.Biblioteko.Mobile.GlobalStaticResources.__ParseContext_);
    							global::Uno.UI.FrameworkElementHelper.SetBaseUri(c0, "file:///C:/Users/Andrii/Dev/Frebo/Biblioteko/Biblioteko.Mobile.Shared/Assets/Resources/Components.xaml");
    							c0.CreationComplete();
    						}
    						))
    					;
    					_Entry2_1Initialized = true;
    				}
    				return __Entry2_1BackingField;
    			}
    		}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/code-generationkind/bugproject/styling 👔

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions