Describe the bug
When Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride is non-empty, ResourceMap.TryGetValue(key, explicitResourceContext) resolves the resource using the global override instead of explicitResourceContext.QualifierValues["Language"]. The context still reports the requested language, but the returned candidate has the override language. This prevents an app from loading a string in a second language while its UI language is overridden.
Observed with Windows App SDK 2.4.0 and a PRI containing en-US, ru-RU, and kk-KZ variants of the same key. With no PrimaryLanguageOverride, the same contexts return the correct translations.
Steps to reproduce the bug
- Create a PRI with the same string key in
Strings/en-US, Strings/ru-RU, and Strings/kk-KZ (for example, Country = Kazakhstan / Казахстан / Қазақстан).
- Load that PRI using
Microsoft.Windows.ApplicationModel.Resources.ResourceManager. In an unpackaged .NET app, pass the PRI path to the constructor.
- Set
Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "en-US".
- Run:
var manager = new ResourceManager(priPath);
var map = manager.MainResourceMap.GetSubtree("Resources");
foreach (var language in new[] { "en-US", "ru-RU", "kk-KZ" })
{
var context = manager.CreateResourceContext();
context.QualifierValues["Language"] = language;
var candidate = map.TryGetValue("Country", context);
Console.WriteLine($"{language}: {candidate?.QualifierValues["Language"]}: {candidate?.ValueAsString}");
}
Actual result with PrimaryLanguageOverride en-US: all three lookups return the en-US candidate. For example, ru-RU: en-US: Kazakhstan. Without the override, the respective en-US, ru-RU, and kk-KZ candidates are returned. The issue also reproduces in our packaged WinUI test app when its UI language is switched to en-US and a separate localizer requests ru-RU.
Expected behavior
An explicitly supplied ResourceContext with QualifierValues["Language"] = "ru-RU" should select the ru-RU candidate even when the application-wide PrimaryLanguageOverride is en-US. The global override should determine the default context, while the explicit context controls this particular lookup, as described in the Windows App SDK localization documentation.
Screenshots
No response
NuGet package version
2.4.0
Packaging type
Unpackaged
Windows version
No response
IDE
Other
Additional context
Environment: Windows build 26200; Visual Studio 2026; Microsoft.WindowsAppSDK NuGet 2.4.0.
The behavior appears to come from ResourceContext::Apply(): it applies entries from m_qualifierValueMap with MrmSetQualifier, then calls MrmSetQualifier for Language again using ApplicationLanguages::PrimaryLanguageOverride() when non-empty. Source: https://github.com/microsoft/WindowsAppSDK/blob/main/dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/ResourceContext.cpp#L596-L632
The documented explicit-context example uses resourceContext.QualifierValues["Language"] = "de-DE" to load a string for a specific language: https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/mrtcore/localize-strings#load-a-string-for-a-specific-language-or-other-context
As a control, directly calling the native MRM API (MrmCreateResourceContext, MrmSetQualifier, MrmLoadStringResource) on the same PRI returns the requested en-US, ru-RU, and kk-KZ variants even while PrimaryLanguageOverride is en-US. This points to the Windows App SDK ResourceContext wrapper rather than missing PRI translations.
Describe the bug
When Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride is non-empty, ResourceMap.TryGetValue(key, explicitResourceContext) resolves the resource using the global override instead of explicitResourceContext.QualifierValues["Language"]. The context still reports the requested language, but the returned candidate has the override language. This prevents an app from loading a string in a second language while its UI language is overridden.
Observed with Windows App SDK 2.4.0 and a PRI containing en-US, ru-RU, and kk-KZ variants of the same key. With no PrimaryLanguageOverride, the same contexts return the correct translations.
Steps to reproduce the bug
Strings/en-US,Strings/ru-RU, andStrings/kk-KZ(for example,Country = Kazakhstan / Казахстан / Қазақстан).Microsoft.Windows.ApplicationModel.Resources.ResourceManager. In an unpackaged .NET app, pass the PRI path to the constructor.Microsoft.Windows.Globalization.ApplicationLanguages.PrimaryLanguageOverride = "en-US".Actual result with PrimaryLanguageOverride
en-US: all three lookups return the en-US candidate. For example,ru-RU: en-US: Kazakhstan. Without the override, the respective en-US, ru-RU, and kk-KZ candidates are returned. The issue also reproduces in our packaged WinUI test app when its UI language is switched to en-US and a separate localizer requests ru-RU.Expected behavior
An explicitly supplied
ResourceContextwithQualifierValues["Language"] = "ru-RU"should select the ru-RU candidate even when the application-widePrimaryLanguageOverrideisen-US. The global override should determine the default context, while the explicit context controls this particular lookup, as described in the Windows App SDK localization documentation.Screenshots
No response
NuGet package version
2.4.0
Packaging type
Unpackaged
Windows version
No response
IDE
Other
Additional context
Environment: Windows build 26200; Visual Studio 2026; Microsoft.WindowsAppSDK NuGet 2.4.0.
The behavior appears to come from
ResourceContext::Apply(): it applies entries fromm_qualifierValueMapwithMrmSetQualifier, then callsMrmSetQualifierforLanguageagain usingApplicationLanguages::PrimaryLanguageOverride()when non-empty. Source: https://github.com/microsoft/WindowsAppSDK/blob/main/dev/MRTCore/mrt/Microsoft.Windows.ApplicationModel.Resources/src/ResourceContext.cpp#L596-L632The documented explicit-context example uses
resourceContext.QualifierValues["Language"] = "de-DE"to load a string for a specific language: https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/mrtcore/localize-strings#load-a-string-for-a-specific-language-or-other-contextAs a control, directly calling the native MRM API (
MrmCreateResourceContext,MrmSetQualifier,MrmLoadStringResource) on the same PRI returns the requested en-US, ru-RU, and kk-KZ variants even while PrimaryLanguageOverride is en-US. This points to the Windows App SDK ResourceContext wrapper rather than missing PRI translations.