I follow the localization directions from Microsoft at Globalization and localization.
It doesn't work as expected and has also obvious mistakes (like confusing app.razor with routes.razor).
Anyway, localization starts to work, according to instruction (dynamically set the server-side culture by user preference), with the following change.
Instead of
var supportedCultures = new[] { "en-US", "es-CR" };var localizationOptions = new RequestLocalizationOptions() .SetDefaultCulture(supportedCultures[0]) .AddSupportedCultures(supportedCultures) .AddSupportedUICultures(supportedCultures); app.UseRequestLocalization(localizationOptions);I use:
public static CultureInfo[] SupportedCultures = [ new CultureInfo("el-GR"), new CultureInfo("en-US"), ];builder.Services.AddLocalization();builder.Services.Configure<RequestLocalizationOptions>(options =>{ options.SupportedCultures = SupportedCultures; options.SupportedUICultures = SupportedCultures; options.RequestCultureProviders.Clear(); options.RequestCultureProviders.Insert(0, new CookieRequestCultureProvider()); options.DefaultRequestCulture = new RequestCulture(culture: "el-GR");});builder.Services.AddControllers();The problem is that every culture change is filled with exceptions:
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Net.WebSockets.dll
Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dll
As the app is restarted, all server interactive components are disposed and re-initialized several times (during prerender then for rendering etc.).
These 5 exceptions are thrown with an empty template project. If the project grows bigger then my screen is filled with exceptions. It looks like all the components created, even if I do take care to gracefully dispose my own code, Microsoft hasn't done the same for its own code.
Does anyone have any idea?
Update:By adding a couple of working components the number of exceptions is frightening:
Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'System.InvalidOperationException' in Microsoft.JSInterop.dllException thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dllException thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dllException thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'System.IO.IOException' in System.Private.CoreLib.dllException thrown: 'System.InvalidOperationException' in Microsoft.JSInterop.dllException thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dllException thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dllException thrown: 'System.IO.IOException' in System.Private.CoreLib.dllException thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'System.InvalidOperationException' in Microsoft.JSInterop.dllException thrown: 'System.IO.IOException' in System.Private.CoreLib.dllException thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dllException thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dllException thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'System.Net.WebSockets.WebSocketException' in System.Net.WebSockets.dllException thrown: 'System.InvalidOperationException' in Microsoft.JSInterop.dllException thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dllException thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dllException thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dllException thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.dllException thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.dllException thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.dll<Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.dll<Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll<Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll