Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor web app, global InteractiveServer, .NET 9. Localization. During culture change strange exceptions occur #60993

Closed
nefen opened this issue Mar 18, 2025 · 6 comments
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue

Comments

@nefen
Copy link

nefen commented Mar 18, 2025

I used the Blazor Web App (.net-9.0.3) template to create a project with global interactivity (InteractiveServer).

I followed the localization directions from Microsoft at Globalization and localization in paragraph Dynamically set the server-side culture by user preference.

It didn't work as expected and has also obvious mistakes (like confusing app.razor with routes.razor).

Anyway, I fixed localization with small adaptations 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();

So, culture changes, BUT

during debugging, in every culture change, output window 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

All these exceptions maybe are thrown due to violent app restar. 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.

By adding a couple of working components the number of exceptions become frightening:

Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Net.WebSockets.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.JSInterop.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.dll
Exception thrown: 'System.InvalidOperationException' in Microsoft.AspNetCore.Components.dll
Exception 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

Is this nornal? Have I made something wrong?

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Mar 18, 2025
@javiercn
Copy link
Member

@nefen thanks for contacting us.

Do you see these errors only in Visual Studio or do you also see them when running from the command line?

Could you provide a public github repository with a repro project so that we can take a look at your exact changes?

@javiercn javiercn added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue labels Mar 19, 2025
@nefen
Copy link
Author

nefen commented Mar 19, 2025

@javiercn thank you for your prompt reply.
First I want to tell you that none of this exceptions are shown on the cmd window. I only see them in the output window inside Visual Studio.
Now, I am not in my developing machine. I am on a different laptop.
I prepared a repro project, but when I run it I couldn't see any of these exceptions.
Then I pulled my project and run it in this laptop, but I cannot see any exceptions thrown too...
I do not understand what is going on, but I have seen similar patterns especially with exceptions from Aspnet secutiry modules during start-up, that have been disappeared after a fresh clone and reappeared.
Sometimes I have noticed that hot-reload mess everything up. I do not know if there is additionally something else that might cause similar issues.
I will check again and come back. I am sure that cleaning the solution and deleting all obj/bin folders do not solve the issue, as I tried it several times before opening this issue, and at the moment I cannot think anything else that might help me with this issue.

@dotnet-policy-service dotnet-policy-service bot added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Mar 19, 2025
@nefen
Copy link
Author

nefen commented Mar 20, 2025

@javiercn i checked the development machine. I am flood with the exceptions. It runs OS
Windows 10 Pro
Version 22H2
Installed on ‎4/‎11/‎2024
OS build 19045.5608
Experience Windows Feature Experience Pack 1000.19061.1000.0

The other machine that didn't throw exceptions is a Windows 11 machine.
In my development machine, I also updated Visual studio, but nothing changed.

I can ignore them, but I feel uncomfortable. Is there any additional info that I might extract and send to you to assist me?

@javiercn
Copy link
Member

javiercn commented Mar 20, 2025

@nefen thanks for the additional details.

Does this happen with a non-blazor project? It sounds like it's not something Blazor specific from what I can tell. Those exceptions are coming from the runtime and only happen in VS.

If things work from the command line in release mode and you don't see any exception in the app, you should be good. For what I know, those exceptions might not even be from the program itself.

@javiercn javiercn added Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Mar 20, 2025
Copy link
Contributor

Hi @nefen. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@nefen
Copy link
Author

nefen commented Mar 22, 2025

As I had explained all these exceptions were thrown only to my development laptop and not in another one.

I uninstalled Visual Studio and reinstalled it.

The exceptions have been gone (although thie time something went wrong on the installation with JIT!)

@nefen nefen closed this as completed Mar 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue
Projects
None yet
Development

No branches or pull requests

2 participants