0

I'm using JSON transcoding in a .NET 7 gRPC service. A certain element in the proto file is using the Any element:

google.protobuf.Any payload = 3 [(validate.rules) = {any:{required:true}}];

When I'm sending a request containing the Any element

Request exerpt:

"inputPayload": {
  @type": "type.googleapis.com/myRequestPayload",
  "foo": "bar",
}

it gives this response:

{
    "code": 3,
    "message": "Type registry has no descriptor for type name 'myRequestPayload'.",
    "details": []
}

I do have another proto with the definition of myRequestPayload. How can I register this type so that the gRPC service understands the contents of the Any element?

ngruson
  • 1,176
  • 1
  • 13
  • 25

1 Answers1

0

While I haven't tried it, I'd expect you to set GrpcJsonTranscodingOptions.TypeRegistry to a type registry containing the relevant type, e.g.

var registry = TypeRegistry.FromFiles(MyProtoReflection.FileDescriptor);
services.AddGrpc().AddJsonTranscoding(options => options.TypeRegistry = registry);

Where MyProtoReflection is the name of the reflection class generated from the proto.

(You could specify just the message types you expect to be in the registry, but I'd normally do it via a set of files...)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • Thanks Jon for the quick reply, I added the required reflection descriptors and it's working indeed. I wasn't aware of these options. – ngruson Mar 09 '23 at 13:28