Issue Report
When you try to Serialize a class generated using a .proto file the ProtobufMessageSerializer
throw an Exception System.InvalidOperationException Type is not expected, and no contract can be inferred: ...
The Current Serializer appears to work only for .Net classes decorated with attributes DataContract
, DataMember
Expected Behavior
Should be able to Serialize a class generated using a proto file.
A reference here: https://developers.google.com/protocol-buffers/docs/csharptutorial#parsing_and_serialization
Actual Behavior
When you try to Serialize a class generated using a .proto file the ProtobufMessageSerializer
throws an Exception System.InvalidOperationException Type is not expected, and no contract can be inferred: ...
Steps to Reproduce the Issue
- Design a simple Protobuf file (from the Protobuf documentation)
`message Person {
string name = 1;
int32 id = 2; // Unique ID number for this person.
string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
string number = 1;
PhoneType type = 2;
}
repeated PhoneNumber phones = 4;
google.protobuf.Timestamp last_updated = 5;
}
// Our address book file is just one of these.
message AddressBook {
repeated Person people = 1;
}`
protoc -I=$SRC_DIR --csharp_out=$DST_DIR $SRC_DIR/addressbook.proto
`
Person msg = new Person
{
Id = 1234,
Name = "John Doe",
Email = "[email protected]",
Phones = { new Person.Types.PhoneNumber { Number = "555-4321", Type = Person.Types.PhoneType.Home } }
};
var serializer = new ProtobufMessageSerializer();
var byteArray1 = serializer.Serialize(msg ); // An Exception ara going to happen here
`