dotnet
protocol_error
ai_generated
true
Grpc.Core.RpcException: Status(StatusCode="InvalidArgument", Detail="Invalid message length: received 1048577 bytes, maximum is 1048576.")
ID: dotnet/grpc-invalid-message-length
85%Fix Rate
87%Confidence
1Evidence
2023-08-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| Grpc.Core 2.46 | active | — | — | — |
| Grpc.Net.Client 2.52 | active | — | — | — |
| .NET 6.0 | active | — | — | — |
| .NET 7.0 | active | — | — | — |
| .NET 8.0 | active | — | — | — |
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).
generic中文
gRPC 请求或响应消息超过了服务器或客户端配置的最大大小限制,默认值为 1 MB(1048576 字节)。
Official Documentation
https://learn.microsoft.com/en-us/aspnet/core/grpc/configurationWorkarounds
-
90% success Increase the maximum message size on the server in Program.cs: services.AddGrpc(options => options.MaxReceiveMessageSize = 2 * 1024 * 1024); // 2 MB
Increase the maximum message size on the server in Program.cs: services.AddGrpc(options => options.MaxReceiveMessageSize = 2 * 1024 * 1024); // 2 MB
-
85% success On the client side, set MaxReceiveMessageSize on GrpcChannelOptions: var channel = GrpcChannel.ForAddress("https://localhost:5001", new GrpcChannelOptions { MaxReceiveMessageSize = 2 * 1024 * 1024 });
On the client side, set MaxReceiveMessageSize on GrpcChannelOptions: var channel = GrpcChannel.ForAddress("https://localhost:5001", new GrpcChannelOptions { MaxReceiveMessageSize = 2 * 1024 * 1024 });
中文步骤
在服务器端 Program.cs 中增加最大消息大小:services.AddGrpc(options => options.MaxReceiveMessageSize = 2 * 1024 * 1024); // 2 MB
在客户端设置 GrpcChannelOptions 上的 MaxReceiveMessageSize:var channel = GrpcChannel.ForAddress("https://localhost:5001", new GrpcChannelOptions { MaxReceiveMessageSize = 2 * 1024 * 1024 });
Dead Ends
Common approaches that don't work:
-
80% fail
This removes all size limits, potentially leading to memory exhaustion or denial-of-service attacks.
-
60% fail
Compression reduces size but may not bring it under the limit if the original is too large; also requires server support.