I am using GRPC on top of ASPNETCore, also have a model like this:
syntax = "proto3";
message Blob {
string id = 1;
string path = 2;
}
The problem is that when i try to set the path
property to null, It throws an ArgumentException
.
simply running this code:
new Blob { Path = null };
Results into this:
System.ArgumentNullException: Value cannot be null. (Parameter 'value')
at Google.Protobuf.ProtoPreconditions.CheckNotNull[T](T value, String name)
at Grpc.Blob.set_Path(String value)
Protobuf has no concept of null; with proto3 treating en empty string as "default, do not send", this means there is no payload difference between null
and ""
. So: perhaps don't try and send null
?
Alternatively: protobuf-net (which works fine with gRPC via protobuf-net.Grpc, which just attaches to the Google/Microsoft bits) would work fine here, and since it is not tied to proto3, it can be made to treat null
and ""
differently (sending ""
explicitly as a zero length string and not sending null
at all). You don't need a .proto for protobuf-net, but if you have one: https://protogen.marcgravell.com/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With