SignalR .NET Core:写入消息失败。中止连接。值不能为空。 (参数'inputType')

SignalR .NET Core: Failed writing message. Aborting connection. Value cannot be null. (Parameter 'inputType')

我正在使用 SignalR 流式传输一些实时数据。我可以完美地连接我的 js 客户端,但是只要我调用一个方法,我就会收到下面的错误,只有当我使用 signalR 的调试日志时(否则它只会在调用时抛出 Error: Invocation canceled due to the underlying connection being closed.)。如果我在调用该方法的集线器中放置断点,他会通过它,但不知何故我仍然得到这个隐藏的错误。

dbug: Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher[1]
      Received hub invocation: InvocationMessage { InvocationId: "0", Target: "WatchSimulations", Arguments: [ System.Collections.Generic.List`1[System.Guid] ], StreamIds: [  ] }.
Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher: Debug: Received hub invocation: InvocationMessage { InvocationId: "0", Target: "WatchSimulations", Arguments: [ System.Collections.Generic.List`1[System.Guid] ], StreamIds: [  ] }.
dbug: Microsoft.AspNetCore.SignalR.HubConnectionContext[6]
Microsoft.AspNetCore.SignalR.HubConnectionContext: Debug: Failed writing message. Aborting connection.

System.ArgumentNullException: Value cannot be null. (Parameter 'inputType')
   at System.Text.Json.JsonSerializer.Serialize(Utf8JsonWriter writer, Object value, Type inputType, JsonSerializerOptions options)
   at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteCompletionMessage(CompletionMessage message, Utf8JsonWriter writer)
   at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteMessageCore(HubMessage message, IBufferWriter`1 stream)
   at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteMessage(HubMessage message, IBufferWriter`1 output)
   at Microsoft.AspNetCore.SignalR.HubConnectionContext.WriteCore(HubMessage message, CancellationToken cancellationToken)
      Failed writing message. Aborting connection.
Microsoft.AspNetCore.SignalR.HubConnectionHandler: Debug: OnConnectedAsync ending.
      System.ArgumentNullException: Value cannot be null. (Parameter 'inputType')
Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport: Debug: Waiting for the client to close the socket.
         at System.Text.Json.JsonSerializer.Serialize(Utf8JsonWriter writer, Object value, Type inputType, JsonSerializerOptions options)
         at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteCompletionMessage(CompletionMessage message, Utf8JsonWriter writer)
         at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteMessageCore(HubMessage message, IBufferWriter`1 stream)
         at Microsoft.AspNetCore.SignalR.Protocol.JsonHubProtocol.WriteMessage(HubMessage message, IBufferWriter`1 output)
         at Microsoft.AspNetCore.SignalR.HubConnectionContext.WriteCore(HubMessage message, CancellationToken cancellationToken)
dbug: Microsoft.AspNetCore.SignalR.HubConnectionHandler[6]
      OnConnectedAsync ending.
dbug: Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport[7]
      Waiting for the client to close the socket.
dbug: Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport[2]
      Socket closed.
Microsoft.AspNetCore.Http.Connections.Internal.Transports.WebSocketsTransport: Debug: Socket closed.

中心:

    [Authorize]
    public class ProgressHub : Hub<IProgressHub>
    {
        public Task WatchSimulations(List<Guid> simulationUids)
        {
            var tasks = new List<Task>();
            simulationUids.ForEach(id =>
            {
                tasks.Add(
                    Groups.AddToGroupAsync(Context.ConnectionId, id.ToString())
                );
            });
            return Task.WhenAll(tasks);
        }
    }

我正在使用 .NET Core 3.1 和@microsoft/signalr 5.0.0.

有人认识这个问题吗?

谢谢!

如果您从 3.1 项目中引用 System.Text.Json 5.0,就会发生此错误。 3.1.11 将包含一个修复程序。现在,您可以避免更新 System.Text.Json,将您的应用程序升级到 net5.0,或者改用 Newtonsoft.Json 而不是 System.Text.Json。