Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I send a google.protobuf.Value object using protobuf-net.Grpc and code-first? #335

Open
glazkovalex opened this issue Sep 24, 2024 · 0 comments

Comments

@glazkovalex
Copy link

The protobuf format has the type google.protobuf.Value described in Create Protobuf messages for .NET apps.
There is also a Google.Protobuf.WellKnownTypes.Value type in the Google.Protobuf, Version=3.28.0.0 library.

I can send google.protobuf.Value with a message described by such a proto-file:

import "google/protobuf/struct.proto";

message Status {
// ...
    google.protobuf.Value data = 3;
}

As a result, I will get a generated dot with a "data" field of the type Google.Protobuf.WellKnownTypes.Value. I can assign an arbitrary JsonDocument to this "data" in the following way and everything will be transmitted perfectly.

var dto = new Status();
dto.Data = Google.Protobuf.WellKnownTypes.Value.Parser.ParseJson(myJsonDocument.RootElement.ToString())

I used protobuf-net.Grpc and applied code-first by creating such a dto with the field Google.Protobuf.WellKnownTypes.Value

[DataContract]
public class ObjectTypeDto
{
    [DataMember(Order = 1)]
    public Google.Protobuf.WellKnownTypes.Value Data { get; set; }
}

If I pass my myJsonDocument through it as before, I get an exception: System.InvalidOperationException: No serializer defined for type: Google.Protobuf.WellKnownTypes.Value

How do I send a google.protobuf.Value(Google.Protobuf.WellKnownTypes.Value) object using protobuf-net.Grpc and code-first?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant