1

While serializing a Flags long Enum, protobuf-net throws a System.Overflow exception. Here's a schematic description of what I'm doing:

Class being serialized:

[ProtoContract()]
public class Entry
{
   [ProtoMember(1)]
   public FancyLongEnum FancyLongEnum {get;set;}
}

The Enum:

[ProtoContract(ImplicitFields = ImplicitFields.AllFields, EnumPassthru = true)]
[Flags]
public enum FancyLongEnum : long
{
    FirstFancyValue = 1,
    [...]
    LastFancyValue = 137438953472
}

The result:

System.OverflowException: Arithmetic operation resulted in an overflow.

A workaround is to use a wrapper long property and ignore the FancyLongEnum during serialization. However, I was hoping there is a cleaner way.

A similar issue was discussed in Error while using ProtoBuf-Net with flags enum. It resulted in a fix to protobuf-net.

How can I make serialization work directly, without resorting to wrapper property?

Community
  • 1
  • 1
Alan Stark
  • 103
  • 1
  • 8
  • That appears to be a bug, plain and simple. I have logged this for you: https://github.com/mgravell/protobuf-net/issues/142. The workaround is the dummy property; the fix will need library changes. – Marc Gravell Feb 17 '16 at 13:10
  • Thanks for confirming it @MarcGravell! (and for the quick response too) I'll stick with the dummy property for now. Other than that, thank you for this damn fast serialization library! – Alan Stark Feb 17 '16 at 14:04

0 Answers0