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

Resource lookups fail on Windows when merging xaml in Debug #1515

Open
kazo0 opened this issue Jan 7, 2025 · 0 comments
Open

Resource lookups fail on Windows when merging xaml in Debug #1515

kazo0 opened this issue Jan 7, 2025 · 0 comments
Labels
kind/bug Something isn't working

Comments

@kazo0
Copy link
Collaborator

kazo0 commented Jan 7, 2025

When running the Windows sample app in Debug locally, there is a crash with the message saying that it cannot locate the resource MaterialBackgroundBrush.

This is caused by the organization of the ResourceDictionaries when the Xaml Merge target is run and generates for Hot Reload.

By default in Debug, the property BatchMergeGenerateForHotReload is true so it results in a generated xaml file like this:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/Button.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/CalendarDatePicker.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/CalendarView.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/CheckBox.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/ComboBox.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/CommandBar.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/DatePicker.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/FloatingActionButton.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/Flyout.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/HyperlinkButton.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/InfoBar.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/ListView.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/NavigationView/NavigationView_MUX.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/PasswordBox.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/ProgressBar.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/ProgressRing.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/RadioButton.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/RatingControl.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/Ripple.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/Slider.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/TextBlock.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/TextBox.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/TimePicker.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/ToggleButton.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/ToggleSwitch.Base.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/ToggleSwitch.Mobile.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/ToggleSwitch.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Controls/v1/_Resources.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Application/Common/AnimationConstants.xaml" />
        <ResourceDictionary Source="ms-appx:///Uno.Material.WinUI/Styles/Application/Common/TextBoxVariables.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

Which will result in a failure

Setting BatchMergeGenerateForHotReload to false or running in release generates something like this instead:

<ResourceDictionary xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d not_win android ios not_ios xamarin mobile wasm skia contract4NotPresent contract7NotPresent macos lottie_not_win uwp winui" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:um="using:Uno.Material" xmlns:ut="using:Uno.Themes" xmlns:not_win="http://uno.ui/not_win" xmlns:uno="using:Uno.UI.Xaml.Controls" xmlns:android="http://uno.ui/android" xmlns:ios="http://uno.ui/ios" xmlns:not_ios="http://uno.ui/not_ios" xmlns:xamarin="http://uno.ui/xamarin" xmlns:mobile="http://uno.ui/mobile" xmlns:toolkit="using:Uno.UI.Toolkit" xmlns:uuc="using:Uno.UI.Controls" xmlns:wasm="http://uno.ui/wasm" xmlns:controls="using:Microsoft.UI.Xaml.Controls" xmlns:media="using:Microsoft.UI.Xaml.Media" xmlns:primitives="using:Microsoft.UI.Xaml.Controls.Primitives" xmlns:skia="http://uno.ui/skia" xmlns:contract4Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:contract4NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,4)" xmlns:contract7Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:contract7NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,7)" xmlns:not_macos="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:macos="http://uno.ui/macos" xmlns:lottie_not_win="#using:Microsoft.Toolkit.Uwp.UI.Lottie;CommunityToolkit.WinUI.Lottie" xmlns:lottie_win="using:Microsoft.Toolkit.Uwp.UI.Lottie" xmlns:uwp="http://uno.ui/uwp" xmlns:winui="http://uno.ui/winui" xmlns:not_android="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:uuvc="using:Uno.UI.Views.Controls" xmlns:not_mobile="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
  <ResourceDictionary.MergedDictionaries>
    <not_win:ResourceDictionary>
      <lottie_not_win:LottieVisualSource x:Key="MaterialDeterminateAnimation_Uno" uwp:UriSource="embedded://Uno.Material/Uno.Material.Assets.MaterialDeterminate.json" winui:UriSource="embedded://Uno.Material.WinUI/Uno.Material.WinUI.Assets.MaterialDeterminate.json" />
      <lottie_not_win:LottieVisualSource x:Key="MaterialIndeterminateAnimation_Uno" uwp:UriSource="embedded://Uno.Material/Uno.Material.Assets.MaterialIndeterminate.json" winui:UriSource="embedded://Uno.Material.WinUI/Uno.Material.WinUI.Assets.MaterialIndeterminate.json" />
    </not_win:ResourceDictionary>
    <um:MaterialFonts />
    <um:MaterialColorsV1 />
  </ResourceDictionary.MergedDictionaries>
  <ResourceDictionary.ThemeDictionaries>
    <ResourceDictionary x:Key="Light">
      <Color x:Key="ButtonFabLowFabBackgroundColor">#9F9F9F</Color>
      <StaticResource x:Key="MaterialMUXNavigationViewDefaultPaneBackground" ResourceKey="SystemChromeMediumColor" />
      <StaticResource x:Key="MaterialMUXNavigationViewExpandedPaneBackground" ResourceKey="SystemChromeMediumColor" />
      <StaticResource x:Key="MaterialMUXNavigationViewTopPaneBackground" ResourceKey="SystemChromeMediumHighColor" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackground" ResourceKey="SystemControlTransparentBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackgroundPointerOver" ResourceKey="SystemControlHighlightListLowBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackgroundPressed" ResourceKey="SystemControlHighlightListMediumBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackgroundDisabled" ResourceKey="SystemControlTransparentBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackgroundChecked" ResourceKey="SystemControlTransparentBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackgroundCheckedPointerOver" ResourceKey="SystemControlHighlightListLowBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackgroundCheckedPressed" ResourceKey="SystemControlHighlightListMediumBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackgroundCheckedDisabled" ResourceKey="SystemControlTransparentBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackgroundSelected" ResourceKey="SystemControlTransparentBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackgroundSelectedPointerOver" ResourceKey="SystemControlHighlightListLowBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackgroundSelectedPressed" ResourceKey="SystemControlHighlightListMediumBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemBackgroundSelectedDisabled" ResourceKey="SystemControlTransparentBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemForeground" ResourceKey="SystemControlForegroundBaseHighBrush" />
      <StaticResource x:Key="MaterialMUXNavigationViewItemForegroundPointerOver" ResourceKey="SystemControlHighlightAltBaseHighBrush" />

And with that merged xaml we do not see a crash

@kazo0 kazo0 added the kind/bug Something isn't working label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant