2

I'm using protobuf-net.grpc and in general the setup is working, but now I ran into an issue: one of the message objects cannot be used as service method parameter.

Consider the following service definition:

[ServiceContract]
public interface IFooService
{
    [OperationContract]
    public ValueTask<FooResponse> Foo(FooRequest req); // works

    [OperationContract]
    public ValueTask<BarResponse> Bar(FooDto dto); // FooDto cannot be serialized, ignoring
}

[ProtoContract]
public sealed class FooRequest 
{
    [ProtoMember(1)]
    FootDto Foo {get; set;}
}

[ProtoContract]
public sealed class FootDto 
{
    [ProtoMember(1)]
    int Id {get; set;}
    // many other properties
}

Note that FooRequest contains FooDto and it can be serialized without any issues sending and receiving. But if I use it directly as a parameter of the service I get a message that it cannot be serialized and that this service method will be ignored (so the endpoint will return an Unimplemented error when called).

I suppose it has to do with grpc specifics, but simply don't understand why the same object can be serialized if used as part of a message but not on its own.

It is working using the wrapper object, but I would like to know why this is happening anyway.

marce
  • 781
  • 1
  • 10
  • 20
  • 2
    "I suppose it has to do with grpc specifics" - I wrote all the code-first pieces here, and I have *no clue* what is going wrong here; I'll investigate (I know *you* know this, but: cross-reference for other folks: https://github.com/protobuf-net/protobuf-net.Grpc/issues/306) – Marc Gravell Aug 18 '23 at 09:59

0 Answers0