# proto：无法解析 "type.googleapis.com/pb.Payment"

- **ID:** `go/proto-any-unmarshal-type-not-found`
- **领域:** go
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

protojson 或 proto.Unmarshal 遇到 Any 消息，其内嵌 type URL 未在全局类型注册表中注册。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| google.golang.org/protobuf v1.30+ | active | — | — |

## 解决方案

1. **** (93% 成功率)
   ```
   import _ "example.com/project/pb" // triggers init() registration
// or explicit:
protoregistry.GlobalTypes.RegisterMessage(paymentpb.Payment{}.ProtoReflect().Type())
   ```
2. **** (88% 成功率)
   ```
   opts := protojson.UnmarshalOptions{
    Resolver: protoregistry.GlobalTypes,
}
if err := opts.Unmarshal(data, msg); err != nil {
    return err
}
   ```

## 无效尝试

- **** — Any.Value contains a serialized message with a type prefix; direct assignment yields garbage. (95% 失败率)
- **** — Works only if the caller knows the type; defeats the purpose of Any and breaks polymorphic dispatch. (60% 失败率)
