protobuf-net / protobuf-net.Grpc

GRPC bindings for protobuf-net and grpc-dotnet
Other
846 stars 106 forks source link

Inconsistency: Using protobuf-net changes how dictionaries with nullable value types are deserialized #329

Open helm100 opened 1 week ago

helm100 commented 1 week ago

I've found that for gRpc calls, the deserialization of dictionaries with nullable value types changes, purely by including/removing the protobuf-net.Grpc.AspNetCore.Reflection package.

Setup:

Data contract:

[DataContract]
public class TestDataContract
{
    [DataMember(Order = 1)]
    public IDictionary<string, string?> Test { get; set; } = new Dictionary<string, string?>();
}

Service:

[gRpcService]
public class TestGrpcService : ITestGrpc
{
    public async Task<TestDataContract> TestAsync(CallContext context = default)
    {
        return new TestDataContract {
            Test = new Dictionary<string, string?>() { { "test1", "blabla" }, { "test", null } }
        };
    }
}

Client:

...
var response = await testGrpcClient.Test();
...

WITH package, response = { { "test1", "blabla" }, { "test", "" } } WITHOUT package, response = { { "test1", "blabla" }, { "test", null } }

I'm using protobuf-net.Grpc.AspNetCore.Reflection --version 1.1.1