# rpc 错误：代码 = InvalidArgument 描述 = 字段 age 期望字符串，但得到数字

- **ID:** `go/grpc-invalid-argument-field-type`
- **领域:** go
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

protobuf 消息字段类型不匹配；例如，在期望字符串的地方发送了整数。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.56.x | active | — | — |
| 1.57.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   string age = 1; protoc --go_out=. *.proto
   ```
2. **** (90% 成功率)
   ```
   req := &pb.Person{Age: strconv.Itoa(30)}
   ```
3. **** (85% 成功率)
   ```
   if _, ok := req.Age.(string); !ok { return status.Error(codes.InvalidArgument, "age must be string") }
   ```

## 无效尝试

- **Continuing to send incorrect type.** — Same error persists. (100% 失败率)
- **Using type assertion without changing proto.** — Proto definition determines wire format. (80% 失败率)
- **Blaming server for type checking.** — Client must follow proto definition. (50% 失败率)
