Microsoft JsInterop Disconnect

My Radzen Blazor Webapp is throwing:

|16:54:32:342|Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
|16:54:32:594|Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
|16:54:32:594|Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll

When refreshing the homepage or navigating to a different page. This stops most buttons from working.

I created a fresh Blazor Webapp project targeting .NET 8.0 and followed the getting started steps for Radzen: Get Started | Free UI Components by Radzen

The blank blazor app works fine, but as soon as I finish the Radzen setup. I get the same issue as in my main project - the three exceptions above, in my console output and a "disconnect" in my browser network

Hi @BlazingMonk40,

We are not aware of such exception. Did you enable interactivity in your app? How can we reproduce this error? Where do you see those exceptions?

Hey @korchev,

Thanks for reaching out. This error seems to have just started around the second week of April.

I will mention that my main project that I am encountering this error in was created back in May of 2023. The two "render-mode"(s) defined in the project are in the _Host.cshtml and _Layout.cshtml and are set to ServerPrerendered.

Hopefully this extra information is useful, I really appreciate your time.

Steps I followed to reproduce the error in a new blazor template:

Create New Project in VS2022
Blazor Web App Template
Framework .NET 8.0
Authentication: None
Configure for Https: Not Checked
Render mode: Server
Interactive Location: Global

Install Radzen 6.6.1 from Nuget Package Manager
Follow Radzen Getting Started Steps
Set all Render modes to InteractiveServer

Run the app, refresh the site and see the following errors in the Console Output:

16:43:48:042 Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
16:43:48:042 Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
16:43:48:042 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
16:43:48:042 Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
16:43:48:042 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
16:43:48:042 Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Net.WebSockets.dll
16:43:48:042 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
16:43:48:042 Exception thrown: 'System.Net.WebSockets.WebSocketException' in System.Private.CoreLib.dll
16:43:48:042 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
16:43:48:302 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
16:43:48:302 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
16:43:48:302 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
16:43:48:302 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
16:43:48:302 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.AspNetCore.Components.Server.dll
16:43:48:302 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in Microsoft.JSInterop.dll
16:43:48:302 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
16:43:48:302 Exception thrown: 'Microsoft.JSInterop.JSDisconnectedException' in System.Private.CoreLib.dll
16:43:52:803 The thread 42836 has exited with code 0 (0x0).

I am afraid that without the full stacktrace we can't tell more (you also didn't specify what Radzen components to test with). I don't think we have released anything in April that could lead to such exceptions.

In general JSDisconnectedExceptions occur when something tries to use JS interop after the Blazor server socket has been disconnected for some reason.

I'm not sure that I can provide a "full stacktrace", I don't receive a stack trace when this occurs. Those "disconnect" exceptions flood the output, seemingly ~6 times for every component on the page. The site does not crash or throw any errors, it just freezes until all of those exceptions have finished writing to the output.

The errors I copied above are direct from the output, but I only copied a few. On my primary application that this is happening to, there are 800+ lines of that DisconnectException in the console. Whichs results in the pages locking up or freezing for 20+ seconds.

Sorry for not specificing the Radzen component used in the test. I had meant to imply that I was testing the RadzenButton component supplied from the Getting Started procedure. I will mention that the errors still occur in my test project without the Radzen component present. But, the errors are not present in a Blazor-only project, one without the Radzen extension package.

By breakpointing my project I have found the entry of where the exception is being thrown:

RadzenComponent.cs - Line 216-236

public virtual void Dispose()
{
disposed = true;
reference?.Dispose();
reference = null;
if (IsJSRuntimeAvailable)
{
if (ContextMenu.HasDelegate)
{
JSRuntime.InvokeVoidAsync("Radzen.removeContextMenu", UniqueID);
}
if (MouseEnter.HasDelegate)
{
JSRuntime.InvokeVoidAsync("Radzen.removeMouseEnter", UniqueID);
}
if (MouseLeave.HasDelegate)
{
JSRuntime.InvokeVoidAsync("Radzen.removeMouseLeave", UniqueID);
}
}
}

The exception I am experiencing is coming from ln229 and 233 :
JSRuntime.InvokeVoidAsync("Radzen.removeMouseEnter", UniqueID);
JSRuntime.InvokeVoidAsync("Radzen.removeMouseLeave", UniqueID);

I was thinking that it was an issue with Radzen components disposing, but the fact that it still occurs with only the Radzen extension loaded and not any Radzen components rendering on the site. I'm really not sure what is going on.

I want to be clear that I am not blaming Radzen. I love the service you all provide, Radzen components and Radzen Blazor Studio are amazing tools. Saved me months of development on the multiple enterprise projects I've been developing over the past year.

Please let me know what other information you may need, or questions you may have.

We need a reproduction of the exception somehow.

Hey Korchev,

I just published the test project to a github repo. Is it alright if I post that url here? I'm relatively new to the forums here, just want to make sure I'm not breaking community guidelines.

Sure. You can post the link. Alternatively you can send it to info@radzen.com in case you have an active subscription.

I sent an email with the same subject as this topic.

Thank you for your help Korchev, I really appreciate it.

I ran the linked app and refreshed my browser at least twenty times. I saw no exception logged in the command prompt window (I ran the app with dotnet run). What should I do in order to reproduce the problem?
jsinterop-app

Hey Korchev,

So, I've done more testing on my side. And I think I've come to the conclusion that it must be an issue specifically with running the app through Visual Studio 2022. I ran both of my projects with dotnet run and did not experience the JSDisconnectException. And am not experiencing it when publishing to IIS either.

The only time I've been able to produce the error is when running the projects from VS22. But, again, (it seems) to only occur when the Radzen extension is loaded into the project. I'm certain that this is a new issue (within the last 30 days) because development/testing of my primary application is severely hindered by the site freezing during those JSInteropDisconnects. I would have noticed had it been happening earlier.

This test project does not appear to freeze, which i believe is due to so few components on the page. In my main project I get 800+ of those interop exceptions in the debug output console within VS22, which can take upwards of 20 seconds to finish (only ~10 appear with each refresh of the test project).

I have never seen the exception appear in the command prompt that hosts the app. Only in the VS22 Debug Output console. See below:

What should I do in order to reproduce the problem?

I would ask that, if possible, you try to open and run the solution with VS22.

Please let me know your thoughts!

Again, thank you for your continued support!

jsinteropvs22

I ran it with VS2022 with the extension loaded in design time (seen in the background). Refreshed a few dozen times - not a single exception.
vs-jsinterop

I have just pushed a few changes that should prevent such exceptions from being logged. The change should go live with the upcoming v7.0.0 release next week.

Thanks Korchev!

It's so odd to me that the error was not reproducible on your side. I wonder if it has something to do with my browser version or some local setting on my VS instance...?

If can still reply here next week. I will send an update with my findings from the v7.0.0 release.

Thank you again for your support here, I really appreciate it.