go protobuf_error ai_generated true

cannot use type *v1.FooRequest as type *v2.FooRequest in argument to RegisterFooServer

ID: go/protobuf-mismatch

Also available as: JSON · Markdown
85%Fix Rate
87%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
1 active

Root Cause

Generated protobuf Go code is out of sync with the .proto definitions or incompatible protobuf library versions are mixed. Commonly happens when client and server use different generated code versions.

generic

Workarounds

  1. 92% success Regenerate all protobuf Go code from the same .proto files
    protoc --go_out=. --go-grpc_out=. proto/*.proto
    Ensure all services use the same generated package.

    Sources: https://protobuf.dev/reference/go/go-generated/

  2. 88% success Pin protobuf library versions consistently across all modules
    go get google.golang.org/protobuf@latest
    go get google.golang.org/grpc@latest
    go mod tidy

    Sources: https://pkg.go.dev/google.golang.org/protobuf

Dead Ends

Common approaches that don't work:

  1. Manually edit generated .pb.go files to fix type mismatches 95% fail

    Generated files are overwritten on next protoc run — manual edits are lost and the underlying .proto mismatch remains

  2. Mix google.golang.org/protobuf and github.com/golang/protobuf v1 APIs 80% fail

    The two protobuf Go API versions generate incompatible types — mixing them causes type assertion failures

Error Chain

Leads to:
Preceded by:
Frequently confused with: