This code reproduces the problem:
Type Resolver(int fieldNumber)
{
return typeof(ConsoleColor?);
}
var stream = new MemoryStream();
ConsoleColor? obj = ConsoleColor.Green;
Serializer.NonGeneric.SerializeWithLengthPrefix(stream, obj, PrefixStyle.Base128, 1);
stream.Position = 0;
Serializer.NonGeneric.TryDeserializeWithLengthPrefix(stream, PrefixStyle.Base128, Resolver, out var dd);
//EXCEPTION!!!
I am simply serializing a nullable enum value. But when I try to deserialize, I get below exception:
ProtoBuf.ProtoException: Invalid wire-type; this usually means you have over-written a file without truncating or setting the length; see
https://stackoverflow.com/q/2152978/23354
'
What am I doing wrong? Is there any way to fix or work around the issue? I am using version 2.4.6 of protobuf-net library. (Cannot move to 3.x because I am stuck with .Net Framework 4.0).