{
  "id": "dotnet/grpc-invalid-message-length",
  "signature": "Grpc.Core.RpcException: Status(StatusCode=\"InvalidArgument\", Detail=\"Invalid message length: received 1048577 bytes, maximum is 1048576.\")",
  "signature_zh": "Grpc.Core.RpcException：Status(StatusCode=\"InvalidArgument\", Detail=\"无效消息长度：收到 1048577 字节，最大为 1048576。\")",
  "regex": "Grpc\\.Core\\.RpcException: Status\\(StatusCode=\"InvalidArgument\", Detail=\"Invalid message length: received \\d+ bytes, maximum is \\d+\\.\"\\)",
  "domain": "dotnet",
  "category": "protocol_error",
  "subcategory": null,
  "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).",
  "root_cause_type": "generic",
  "root_cause_zh": "gRPC 请求或响应消息超过了服务器或客户端配置的最大大小限制，默认值为 1 MB（1048576 字节）。",
  "versions": [
    {
      "version": "Grpc.Core 2.46",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Grpc.Net.Client 2.52",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": ".NET 6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": ".NET 7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": ".NET 8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This removes all size limits, potentially leading to memory exhaustion or denial-of-service attacks.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Compression reduces size but may not bring it under the limit if the original is too large; also requires server support.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Increase the maximum message size on the server in Program.cs: services.AddGrpc(options => options.MaxReceiveMessageSize = 2 * 1024 * 1024); // 2 MB",
      "success_rate": 0.9,
      "how": "Increase the maximum message size on the server in Program.cs: services.AddGrpc(options => options.MaxReceiveMessageSize = 2 * 1024 * 1024); // 2 MB",
      "condition": "",
      "sources": []
    },
    {
      "action": "On the client side, set MaxReceiveMessageSize on GrpcChannelOptions: var channel = GrpcChannel.ForAddress(\"https://localhost:5001\", new GrpcChannelOptions { MaxReceiveMessageSize = 2 * 1024 * 1024 });",
      "success_rate": 0.85,
      "how": "On the client side, set MaxReceiveMessageSize on GrpcChannelOptions: var channel = GrpcChannel.ForAddress(\"https://localhost:5001\", new GrpcChannelOptions { MaxReceiveMessageSize = 2 * 1024 * 1024 });",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在服务器端 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 });"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://learn.microsoft.com/en-us/aspnet/core/grpc/configuration",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2023-08-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}