# Grpc.Core.RpcException: Status(StatusCode="ResourceExhausted", Detail="Received message larger than max (4194304 vs. 4194304)")

- **ID:** `dotnet/grpc-client-max-message-size`
- **Domain:** dotnet
- **Category:** protocol_error
- **Error Code:** `ResourceExhausted`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The gRPC client or server has a default maximum message size of 4 MB, and the response payload exceeds this limit, causing the channel to reject it.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| .NET 6.0 | active | — | — |
| .NET 7.0 | active | — | — |
| .NET 8.0 | active | — | — |
| Grpc.Net.Client 2.49+ | active | — | — |
| Grpc.AspNetCore 2.49+ | active | — | — |

## Workarounds

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.** (95% success)
   ```
   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.** (85% success)
   ```
   Stream the large payload using server-streaming gRPC instead of unary calls to avoid hitting the message size limit.
   ```

## Dead Ends

- **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% fail)
- **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% fail)
