Events
Mar 31, 11 PM - Apr 2, 11 PM
The ultimate Microsoft Fabric, Power BI, SQL, and AI community-led event. March 31 to April 2, 2025.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
This article provides instructions on how to diagnose ASP.NET Core app localization issues.
Localization middleware order
The app may not localize because the localization middleware isn't ordered as expected.
To resolve this issue, ensure that localization middleware is registered before MVC middleware. Otherwise, the localization middleware isn't applied.
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddMvc();
}
Localization resources path not found
Supported Cultures in RequestCultureProvider don't match with registered once
ASP.NET Core has predefined rules and guidelines for localization resources file naming, which are described in Globalization and localization in ASP.NET Core.
Common causes of resources not being found include:
.resx
) or the localizer request.Debug
log level) for more details about the missing resources.Tip
When using CookieRequestCultureProvider, verify single quotes aren't used with the cultures inside the localization cookie value. For example, c='en-UK'|uic='en-US'
is an invalid cookie value, while c=en-UK|uic=en-US
is valid.
ASP.NET Core by default provides a way to allow the class libraries to find their resource files via ResourceLocationAttribute.
Common issues with class libraries include:
The RequestLocalizationOptions class has three default providers:
The CustomRequestCultureProvider allows you to customize how the localization culture is provided. The CustomRequestCultureProvider is used when the default providers don't meet your requirements.
A common reason for a custom provider not working properly is that it isn't the first provider in the RequestCultureProviders list. To resolve this issue:
Insert the custom provider at position zero in the RequestCultureProviders list:
options.AddInitialRequestCultureProvider(
new CustomRequestCultureProvider(async context =>
{
// My custom request culture logic
return new ProviderCultureResult("en");
}));
Insert the custom provider at position zero in the RequestCultureProviders list:
options.RequestCultureProviders.Insert(0,
new CustomRequestCultureProvider(async context =>
{
// My custom request culture logic
return new ProviderCultureResult("en");
}));
When the root namespace of an assembly is different than the assembly name, localization doesn't work by default. To avoid this issue use the RootNamespace
attribute, which is described in Globalization and localization in ASP.NET Core.
Warning
A root namespace issue can occur when a project's name isn't a valid .NET identifier. For instance, my-project-name.csproj
uses the root namespace my_project_name
and the assembly name my-project-name
, which results in this error.
If you use resource files for localization, it's important that they have an appropriate build action. Use Embedded Resource; otherwise, the ResourceStringLocalizer
isn't able to find these resources.
When using the location override using the Sensors pane in Google Chrome or Microsoft Edge developer tools, the fallback language is reset after prerendering. Avoid setting the language using the Sensors pane when testing. Set the language using the browser's language settings.
For more information, see Blazor Localization does not work with InteractiveServer (dotnet/aspnetcore
#53707).
ASP.NET Core feedback
ASP.NET Core is an open source project. Select a link to provide feedback:
Events
Mar 31, 11 PM - Apr 2, 11 PM
The ultimate Microsoft Fabric, Power BI, SQL, and AI community-led event. March 31 to April 2, 2025.
Register todayTraining
Module
Create accessible web apps by using ASP.NET Core - Training
Diagnose and fix common web accessibility issues in an ASP.NET Core application.