uwpuwp-xamlxbox-one

Resource from ResourceDictionary in UWP app only recognized on Xbox


There's a peculiar issue happening on a project I'm working on. Certain resources added to resource dictionaries of an UWP app are not recognized when the app is being run locally on a PC, but they are recognized when run on an Xbox.

When running the app on PC (Debug|x64) from Visual Studio, the following Exception pops up on startup:

Windows.UI.Xaml.Markup.XamlParseException
  HResult=0x802B000A
  Message=The text associated with this error code could not be found.

Cannot find a Resource with the Name/Key SimpleTextBox [Line: 45 Position: 41]
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

This exception triggers on the InitializeComponent method of LoginView.xaml.cs.

The style is defined here and the ResourceDictionary is included here.


Solution

  • I downloaded the original sample repo, and run it on xbox successfully indeed, and failed on PC, and hint

    Cannot find a Resource with the Name/Key ViewModelLocator [Line: 8 Position: 5]'
    

    So we need to add a ViewModelLocator key to file JellyfinStyleResources.DeviceFamily-Desktop.xaml.

    We do this, because on xbox, app will load JellyfinStyleResources without specified platform. But on PC, there exist a file named JellyfinStyleResources.DeviceFamily-Desktop.xaml. Our app will automatically load it's platform related file.

    Then after we add the key above, the compiler will hint more errors about resources missing. If you compare the two files, you will find, the author only write them for xbox, so you need to copy the resources to file JellyfinStyleResources.DeviceFamily-Desktop.xaml.

    After all done, you will find out the app will successfully run on your PC :)


    Or you can just delete the file JellyfinStyleResources.DeviceFamily-Desktop.xaml, run app and done :)