Home > Mobile >  Adding <body href="~/" /> tag to _Layout.cshtml causes Blazor Error: Circuit host no
Adding <body href="~/" /> tag to _Layout.cshtml causes Blazor Error: Circuit host no

Time:09-15

I am working on an Asp.net Core web app in visual studio and I created a razor component that displayed some data and had a button with a function to update a variable that changes the UI. I added the script tag <script src="_framework/blazor.server.js"></script> to _Layout.cshtml to (if I understand correctly) give my razor component its functionality.

The function still wasn't running so I had to add the base tag <base href="~/" /> in the head of the file. It works after doing that.

However, my code queries a database for some data to display in the razor component. When I just limit it to a few rows, it works fine. But when I want to load all the data, the screen displays a message about reconnecting to the server: Reconnecting Image

And the browser console has the following error:

blazor.server.js:1 [2022-09-14T16:01:51.363Z] Error: Connection disconnected with error 'Error: Server returned an error on close: Connection closed with an error.'.
log @ blazor.server.js:1
blazor.server.js:1 Uncaught (in promise) Error: Server returned an error on close: Connection closed with an error.
    at kt._processIncomingData (blazor.server.js:1:70472)
    at connection.onreceive (blazor.server.js:1:64485)
    at o.onmessage (blazor.server.js:1:48819)
blazor.server.js:1 [2022-09-14T16:01:54.366Z] Information: Normalizing '_blazor' to 'https://localhost:7270/_blazor'.
blazor.server.js:1 [2022-09-14T16:01:54.371Z] Information: WebSocket connected to wss://localhost:7270/_blazor?id=WZBsVQi2CxGVCxfmKeTtWw.
blazor.server.js:1 [2022-09-14T16:01:54.372Z] Error: Error: Circuit host not initialized.
log @ blazor.server.js:1

If I remove the base tag, the server reconnecting error doesn't happen and the site can load all the data perfectly, but then my razor component does nothing when I click on a button in it to change the data the UI is displaying.

I have tried just appending the base tag ~/ onto the script tag src but that didn't work. It still has the same problem of not being able to locate the file without the base tag. I also saw this post: Blazor Server - the circuit failed to initialize but trying that solution didn't work as well.

CodePudding user response:

It is likely you are reaching the message limit, which by default is 32KB on SignalR, You can try to

services.AddSignalR(e => 
{
   e.MaximumReceiveMessageSize = xxxxxxxxx;
});

But It is not the best method, The recomment solution is to implement your own hub between client and server and process in chunks and stick it together.

please refer to this link.

  • Related