I've been given a C++ application (a built executable and source code that doesn't build right now) that uses generated proto classes to send protobuf messages. I took the same .proto files it used to generate its classes, and I generated associated classes in a C# app. The intent is to be able to receive and send messages between these apps, using protobuf-net on the C# side. Note that both are using the proto2 format.
Messages with only simple type (e.g. int) members can be serialized and deserialized successfully. However, there seems to be an issue deserializing messages with nested message types into my C# application, e.g.
message Outer {
optional Inner = 1;
}
message Inner {
optional float f = 1;
}
A received message of type "Outer" will fail to deserialize in C# via:
Serializer.Deserialize<T>(new MemoryStream(msg)); // msg is a byte[]
giving an "Invalid Wire Type Exception." I followed the link here, but having looked at those answers, I didn't find anything immediately obvious relating to my situation. I'm 95% sure the source and destination generated classes are the same, the data isn't corrupt, and I'm deserializing to the correct type.
Can I correctly deserialize such nested types? Is there a compatibility issue with the way the classes were generated (and how it serializes) in the C++ app vs the C# app using protobuf-net?
Here is an example project (made in VS 2019 for .NET Core 3.1) which will reproduce the issue.