Skip to content

UnhandledException when using ResourceDictionary with CustomResource and WindowsAppSDK 1.7.25 #10506

@PetarMladenov

Description

@PetarMladenov

Describe the bug

Custom class defined in xaml constructs new CustomXamlResourceLoader in its static constructor. In xaml the setup is the following:

<Application.Resources>
     <ResourceDictionary>
         <ResourceDictionary.MergedDictionaries>
             <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />

	     <ResourceDictionary>

		<local:UserThemeResources x:Key="ResourceLoaderInitializer" />
		
		<ResourceDictionary.MergedDictionaries>
			<ResourceDictionary Source="{CustomResource DarkResourcesPath}"/>
		</ResourceDictionary.MergedDictionaries>
	     </ResourceDictionary>

	<!-- Other merged dictionaries here -->
         </ResourceDictionary.MergedDictionaries>
         <!-- Other app resources here -->
     </ResourceDictionary>
</Application.Resources>

In the constructor of UserThemeResources we set:

CustomXamlResourceLoader.Current = new UserThemeResourceLoader();

This builds and runs fine with WindowsAppSDK 1.6.25.

In 1.7.256 version of SDK we get:

{Microsoft.UI.Xaml.UnhandledExceptionEventArgs}
    Exception: {"The text associated with this error code could not be found.\r\n\r\nNo custom resource loader set. [Line: 17 Position: 27]"}

and also the static constructor of UserThemeResources is not fired at all.

Steps to reproduce the bug

UserThemeResources_Test.zip

Run the application with WindowsAppsSDK 1.7.25 restored. Notice the exception

Expected behavior

No exception and the constructor to fire.

Screenshots

Image

NuGet package version

None

Windows version

Windows 11 (24H2): Build 26100

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions