Repository navigation
Description
The section Client-side prerendering in a Blazor Web App preserves the server's culture (in aspnetcore/blazor/globalization-localization.md and in the ASP.NET Core 11 release notes, aspnetcore/release-notes/aspnetcore-11/includes/blazor.md) shows this opt-out:
builder.Services.AddRazorComponents()
.AddInteractiveWebAssemblyComponents(options =>
{
options.UseCultureFromServer = false;
});This API does not exist in the shipped .NET 11.0.0. The public WebAssemblyComponentsOptions class and the AddInteractiveWebAssemblyComponents(Action<WebAssemblyComponentsOptions>?) overload were removed before release by dotnet/aspnetcore#67367 ("Fix culture persistence to not have public API", fixes dotnet/aspnetcore#66829). The Microsoft.AspNetCore.Components.WebAssembly.Server 11.0.0 package contains only the internal WebAssemblyComponentsServiceOptions, so the sample above doesn't compile.
Actual behavior in 11.0.0
- The setting is configuration-based:
Components:UseCultureFromServer(true/1orfalse/0). It's read by the internalWebAssemblyComponentsServiceOptionsConfiguration. - The default is not simply "on". When the key isn't set, culture capture is enabled only if
IStringLocalizerFactoryis registered on the server, which is the case when the app callsAddLocalization(). - On the client,
WebAssemblyHost.RunAsyncCorecallsCultureStateProvider.ApplyStoredCulture()after user code inProgramand beforeLoadCurrentCultureResourcesAsync().
Why this matters: conflict with the documented client-side culture pattern
The same article's section Dynamically set the client-side culture by user preference recommends reading the culture from local storage and setting CultureInfo.DefaultThreadCurrentCulture/DefaultThreadCurrentUICulture in Program before host.RunAsync().
In a Blazor Web App that:
- calls
AddLocalization()on the server (so capture is on implicitly), - prerenders at least one
InteractiveWebAssemblycomponent (for example inApp.razor, even whenRoutesusesprerender: false), and - doesn't use request localization on the server,
the server's process culture overrides the culture the user selected on the client. Satellite assemblies for the selected culture are never loaded, and the UI stays in the server's language. This silently broke a working language switcher when we upgraded from .NET 10 to .NET 11. Browsers with a non-English language also get the server's culture.
Suggested doc changes
- Replace the opt-out sample with the configuration key, for example in
appsettings.json:{ "Components": { "UseCultureFromServer": false } } - Describe the actual default: enabled when localization services are registered (
AddLocalization), unless the key is set explicitly. - In Dynamically set the client-side culture by user preference, and in any Blazor Web App variant that sets the culture in the client's
Programfile, add a note for .NET 11+. When the server prerenders interactive WebAssembly components, either setComponents:UseCultureFromServertofalse, or flow the same culture to the server, for example with a culture cookie andUseRequestLocalization. - Consider a breaking-change or migration note for 10.0 → 11.0.
Related: dotnet/aspnetcore#63144, dotnet/aspnetcore#67367, dotnet/aspnetcore#66829, dotnet/aspnetcore#70510.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsTriage
Activity