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

- **ID:** `dotnet/signalr-negotiate-version`
- **领域:** dotnet
- **类别:** protocol_error
- **验证级别:** ai_generated
- **修复率:** 88%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| .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 | — | — |

## 解决方案

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

## 无效尝试

- **Set HubConnectionBuilder to use raw WebSockets without negotiation** — Disabling negotiation may bypass version check but causes connection failures if the server requires negotiation for transports like Server-Sent Events. (80% 失败率)
- **Upgrade only the client-side SignalR package to the latest version** — 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. (65% 失败率)
- **Ignore the error and retry connection with exponential backoff** — Retrying does not fix the protocol version mismatch; the negotiate request will fail repeatedly. (95% 失败率)
