BlazorServer在关闭时返回错误:连接关闭了错误

问题描述 投票:0回答:1

我在大火上8。 试图实施通知服务。 从任何剃须刀页面上,我都会将“消息”推向MainLayout页面,以增加通知计数。 我在文件上一直存在错误,我不控制“ Framework/blazor.server.js”:server返回关闭的错误:连接使用错误关闭。”

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)`

我已经尝试以DOC中描述的方式来实现SignalR,但仍然存在相同的错误。我现在正在尝试没有。 我有一些剃须刀和CSHTML页面。 在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();
        }
    }
我缺少一些计算机配置吗? 当我与用户登录时,似乎它被困在无限的循环中,我正在使用

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; });
    
asp.net-core notifications blazor signalr
1个回答
0
投票
检查ASP.NET Core Signalr的源代码后。我发现

GetTarget

存在于.net版本> = 7中。
因此,请更新您的所有软件包(已使用signalr)版本,以更新。
.net6

.net7+enter image description here

enter image description here

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.