# Grpc.Core.RpcException: 状态(StatusCode="ResourceExhausted", Detail="接收的消息大于最大值(4194304 vs. 4194304)")

- **ID:** `dotnet/grpc-client-max-message-size`
- **领域:** dotnet
- **类别:** protocol_error
- **错误码:** `ResourceExhausted`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

gRPC客户端或服务器默认最大消息大小为4 MB，响应负载超过此限制，导致通道拒绝。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| .NET 6.0 | active | — | — |
| .NET 7.0 | active | — | — |
| .NET 8.0 | active | — | — |
| Grpc.Net.Client 2.49+ | active | — | — |
| Grpc.AspNetCore 2.49+ | active | — | — |

## 解决方案

1. ```
   Increase MaxReceiveMessageSize on the client and MaxSendMessageSize on the server to a larger value (e.g., 10 MB) in the gRPC channel and service options.
   ```
2. ```
   Stream the large payload using server-streaming gRPC instead of unary calls to avoid hitting the message size limit.
   ```

## 无效尝试

- **Increasing the client's MaxReceiveMessageSize without adjusting the server's MaxSendMessageSize** — Both client and server enforce limits; if only one side is increased, the other side still rejects the message. (70% 失败率)
- **Disabling compression on the gRPC channel to reduce message size** — Compression reduces size but does not eliminate the hard limit; large payloads still exceed 4 MB. (40% 失败率)
