dotnet protocol_error ai_generated true

Microsoft.AspNetCore.SignalR.HubException: 与服务器协商失败。服务器返回了不支持的协商版本。

Microsoft.AspNetCore.SignalR.HubException: Failed to negotiate with the server. The server returned an unsupported negotiate version.

ID: dotnet/signalr-negotiate-version

其他格式: JSON · Markdown 中文 · English
88%修复率
84%置信度
1证据数
2023-09-05首次发现

版本兼容性

版本状态引入弃用备注
.NET 6.0 active
.NET 7.0 active
.NET 8.0 active
Microsoft.AspNetCore.SignalR.Client 6.0 active
Microsoft.AspNetCore.SignalR.Client 7.0 active
Microsoft.AspNetCore.SignalR.Client 8.0 active

根因分析

SignalR 客户端和服务器协商连接参数;当客户端使用的 SignalR 协议版本过时或不兼容,服务器无法识别时,会出现不支持的协商版本错误。

English

SignalR client and server negotiate connection parameters; an unsupported negotiate version error occurs when the client uses an outdated or incompatible SignalR protocol version that the server does not recognize.

generic

官方文档

https://learn.microsoft.com/en-us/aspnet/core/signalr/troubleshoot

解决方案

  1. 确保客户端和服务器使用相同主版本的 Microsoft.AspNetCore.SignalR(例如均为 6.0.x 或 8.0.x)。检查 .csproj 文件和服务器包。
  2. 如果使用自定义协商端点,更新它以返回包含协议版本 1 或更高版本的正确协商响应。
  3. 降级客户端包以匹配服务器版本:dotnet add package Microsoft.AspNetCore.SignalR.Client --version 6.0.25

无效尝试

常见但无效的做法:

  1. Set HubConnectionBuilder to use raw WebSockets without negotiation 80% 失败

    Disabling negotiation may bypass version check but causes connection failures if the server requires negotiation for transports like Server-Sent Events.

  2. Upgrade only the client-side SignalR package to the latest version 65% 失败

    If the server is an older version, the latest client may introduce a negotiate version the server doesn't support; both sides must be compatible.

  3. Ignore the error and retry connection with exponential backoff 95% 失败

    Retrying does not fix the protocol version mismatch; the negotiate request will fail repeatedly.