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

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

Closed
3 of 12 tasks
BrianDT opened this issue May 21, 2020 · 10 comments · Fixed by #1766
Closed
3 of 12 tasks

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

BrianDT opened this issue May 21, 2020 · 10 comments · Fixed by #1766
Assignees
Labels
area/code-generation Categorizes an issue or PR as relevant to code generation kind/bug Something isn't working project/styling 👔 Categorizes an issue or PR as relevant to element styling

Comments

@BrianDT
Copy link

BrianDT commented May 21, 2020

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?

@BrianDT BrianDT added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels May 21, 2020
@BrianDT
Copy link
Author

BrianDT commented May 21, 2020

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

@Xiaoy312 Xiaoy312 added platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform area/code-generation Categorizes an issue or PR as relevant to code generation platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform and removed triage/untriaged Indicates an issue requires triaging or verification labels May 30, 2020
@Xiaoy312
Copy link
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 */),
-        }
-    };
}

@jeromelaban
Copy link
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

@jeromelaban jeromelaban added project/styling 👔 Categorizes an issue or PR as relevant to element styling priority/important-soon and removed platform/android 🤖 Categorizes an issue or PR as relevant to the Android platform project/styling 👔 Categorizes an issue or PR as relevant to element styling platform/wasm 🌐 Categorizes an issue or PR as relevant to the WebAssembly platform labels May 31, 2020
@davidjohnoliver davidjohnoliver self-assigned this Jun 1, 2020
@davidjohnoliver
Copy link
Contributor

Yes, this should be fixed with #1766.

@xperiandri
Copy link
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 '

@xperiandri
Copy link
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}" />

@xperiandri
Copy link
Contributor

Happen on Android for me

@xperiandri
Copy link
Contributor

Do I need to create a separate issue for this?

@xperiandri
Copy link
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'

@xperiandri
Copy link
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
Labels
area/code-generation Categorizes an issue or PR as relevant to code generation kind/bug Something isn't working project/styling 👔 Categorizes an issue or PR as relevant to element styling
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants