Skip to content

ResourceLoader can throw NullReferenceException in ProcessResourceFile on the first lookup after PrimaryLanguageOverride changes #26636

Open

Description

@juancarlossierra

Current behavior

After ApplicationLanguages.PrimaryLanguageOverride is set at run time, the next ResourceLoader.GetString reloads all resource tables (EnsureLoadersCultures -> ReloadResources -> ProcessAssembly -> ProcessResourceFile). In our app that first lookup intermittently throws:

System.NullReferenceException
   at Windows.ApplicationModel.Resources.ResourceLoader.ProcessResourceFile(...)
   at ...ProcessAssembly
   at ...ReloadResources
   at ...EnsureLoadersCultures
   at Windows.ApplicationModel.Resources.ResourceLoader.GetString(...)
   at (app code building the new UI)

After a failure the resource tables can stay half-populated: pages built afterwards show a mix of the old and the new language until the app restarts.

Reading src/Uno.WinRT/ApplicationModel/Resources/ResourceLoader.static.cs on release/stable/7.0, the reload is lazy and unlocked (ClearResources, _parsedResources.Clear(), re-parse every .upri), and _loaderContext is only updated at its end. We suspect a concurrent first lookup, but have not instrumented Uno to prove the trigger.

Expected behavior

The first lookup after a language change reloads the tables safely, or the reload happens when the override is set.

How to reproduce it

  1. Set ApplicationLanguages.PrimaryLanguageOverride to another language at run time.
  2. Immediately rebuild UI that calls ResourceLoader.GetString (our case: a shell rebuild right after the language change in Settings).
  3. Roughly 3 of 8 switches (EN <-> ES) failed with the exception above on an Android API 35 emulator, Debug build. No minimal repro yet.

This did not happen with Uno 6.7.18.

Workaround

Make one ResourceLoader.GetString call right after setting PrimaryLanguageOverride, before any UI rebuild, and ignore its failure. With that, 0 failures in more than 10 switches.

Environment

  • Uno.Sdk 7.0.22, Uno.WinUI 7.0.65, Skia renderer
  • .NET 10, net10.0-android, Debug, Android API 35 emulator

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions