Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Blazor Server returned an error on close: Connection closed with an error

$
0
0

I am on Blazor 8.Trying to implement a service for notifications.From any Razor Page I shoud push a "message" to the MainLayout Page to increment a notification count.I keep having an error on a file I don't control "framework/blazor.server.js" : Server "returned an error on close: Connection closed with an error."

The trace is :Server returned an error on close: Connection closed with an error.Here is the full trace :

`Completed connection handshake. Using HubProtocol 'blazorpack'.dbug: Microsoft.AspNetCore.SignalR.HubConnectionHandler[2]      Error when processing requests.      System.IO.InvalidDataException: Reading 'target' as String failed.       ---> System.MissingMethodException: Method not found: 'System.String Microsoft.AspNetCore.SignalR.IInvocationBinder.GetTarget(System.ReadOnlySpan`1<Byte>)'.         at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.ReadString(MessagePackReader& reader, IInvocationBinder binder, String field)         --- End of inner exception stack trace ---         at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.ReadString(MessagePackReader& reader, IInvocationBinder binder, String field)         at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.CreateInvocationMessage(MessagePackReader& reader, IInvocationBinder binder, Int32 itemCount)         at Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocolWorker.TryParseMessage(ReadOnlySequence`1& input, IInvocationBinder binder, HubMessage& message)         at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.DispatchMessagesAsync(HubConnectionContext connection)         at Microsoft.AspNetCore.SignalR.HubConnectionHandler`1.RunHubAsync(HubConnectionContext connection)`

I already tried to implement SignalR the way it is describe in the doc, still the same ERROR. I am now trying to do it without.I have some Razor and cshtml pages.In program.cs. builder.Services.AddSingleton<IDataAccess, DataAccess>(); builder.Services.AddSingleton<INotificationService, NotificationService>(); // Ajouter NotificationService

MainLayout.razor

@using Microsoft.AspNetCore.Components.Authorization@inject AuthenticationStateProvider AuthenticationStateProvider@inject INotificationService NotificationService@inject IJSRuntime JS@inject NavigationManager Navigation private int NotificationCount = 0; // Nombre de notifications (initialiséà 0)    private string userId;    private bool ShowNotificationPopup { get; set; } = false;    protected override async Task OnInitializedAsync()    {        var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();        var user = authState.User;        if (user.Identity.IsAuthenticated)        {            userId = user.FindFirst(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier")?.Value;            await PollNotifications();        }    }    private void ToggleNotificationPopup()    {        // Toggle the visibility of the notification popup        ShowNotificationPopup = !ShowNotificationPopup;    }    private async Task PollNotifications()    {        while (true)        {            await Task.Delay(5000); // Poll every 5 seconds            var notifications = await NotificationService.GetUnreadNotificationsAsync(userId);            NotificationCount = notifications.Count;            StateHasChanged();        }    }

Is it some Computer configuration I am missing ?It seems like it is stuck in an infinite loop when I log in with a user, I am using

builder.Services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)                .AddEntityFrameworkStores<ApplicationDbContext>();builder.Services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<IdentityUser>>();builder.Services.AddSignalR(e =>            {                e.EnableDetailedErrors = true;                e.MaximumReceiveMessageSize = 102400000;            });

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>