# Grpc.Core.RpcException: Status(StatusCode="InvalidArgument", Detail="Invalid message length: received 1048577 bytes, maximum is 1048576.")

- **ID:** `dotnet/grpc-invalid-message-length`
- **Domain:** dotnet
- **Category:** protocol_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A gRPC request or response message exceeds the maximum size limit configured on the server or client, defaulting to 1 MB (1048576 bytes).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Grpc.Core 2.46 | active | — | — |
| Grpc.Net.Client 2.52 | active | — | — |
| .NET 6.0 | active | — | — |
| .NET 7.0 | active | — | — |
| .NET 8.0 | active | — | — |

## Workarounds

1. **Increase the maximum message size on the server in Program.cs: services.AddGrpc(options => options.MaxReceiveMessageSize = 2 * 1024 * 1024); // 2 MB** (90% success)
   ```
   Increase the maximum message size on the server in Program.cs: services.AddGrpc(options => options.MaxReceiveMessageSize = 2 * 1024 * 1024); // 2 MB
   ```
2. **On the client side, set MaxReceiveMessageSize on GrpcChannelOptions: var channel = GrpcChannel.ForAddress("https://localhost:5001", new GrpcChannelOptions { MaxReceiveMessageSize = 2 * 1024 * 1024 });** (85% success)
   ```
   On the client side, set MaxReceiveMessageSize on GrpcChannelOptions: var channel = GrpcChannel.ForAddress("https://localhost:5001", new GrpcChannelOptions { MaxReceiveMessageSize = 2 * 1024 * 1024 });
   ```

## Dead Ends

- **** — This removes all size limits, potentially leading to memory exhaustion or denial-of-service attacks. (80% fail)
- **** — Compression reduces size but may not bring it under the limit if the original is too large; also requires server support. (60% fail)
