I am running a gRPC service on .NET Core 3.1 and trying to make calls from a .NET Framework 4.7.2 client. I'm using protobuf-net to reuse existing WCF data contracts. I've noticed the following unexpected client-side behavior today when one of the fields of a response object is non-null.
Grpc.Core.RpcException: 'Status(StatusCode="Internal", Detail="Failed to deserialize response message.")
- Packages: protobuf-net v2.4.4, Grpc v2.30.0, protobuf-net.Grpc v1.0.90, protobuf-net.Grpc.Native v1.0.90, Google.Protobuf v3.12.2
Here is an example that illustrates the general structure of the data contracts - in this case, Response<PersonData> is the response and PersonDataList is the non-null field.
[DataContract]
public class Response<TValue>{
[DataMember(Order = 1)]
public TValue Value;
}
[DataContract]
public class PersonData : Data {
[DataMember(Order = 1)]
public IList<PersonDataItem> PersonDataList;
}
[DataContract]
public PersonDataItem {
[DataMember(Order = 1)]
public PersonDataType Type {get; private set;}
[DataMember(Order = 2)]
public DateTime? Time {get; private set;}
....
[DataContract]
public enum PersonDataType : int {
[EnumMember]
Child = 1,
[EnumMember]
Adult = 2
}
}
[DataContract]
[ProtoInclude(1, typeof(PersonData)]
public class Data {
[DataMember(Order = 1)]
public string Name
}
What stumps me is that I use a similar or same pattern in other data contracts, which throw no exceptions when deserializing the response. I did some searching and found this issue from 2019 that points to different Google.Protobuf versions as a possible source of error (but that doesn't seem to be the case here).
Has anyone seen this exception before? I'm not sure if this is an issue with my data contracts or perhaps with some package version mismatch. Any ideas or suggestions are very appreciated!
I also attempted updating to protobuf-net v3.0.0 but got a new client-side exception for every client call: Grpc.Core.RpcException: 'Status(StatusCode="Unknown", Detail="Exception was thrown by handler. InvalidOperationException: Length mismatch; calculated '63', actual '58'"...) This seems to be a different issue, and my current guess is that it may be related to the breaking changes re: dynamic typing in protobuf-net v3.

