Protobuf-net enumerated exception exception

I have an enum with the flags that I decorate attribute [ProtoMember], which serializes and deserializes in my local field running Win7 x64.

However, my use case includes serializing on a server running Windows Server 2008 R2 Enterprise 64-bit and deserializing in my local field. When I Deserializes, I get an exception: "overflow exception was untreated; arithmetic operation resulted in an overflow." He seems to have been thrown out of ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSerializer.Read (object value, the source ProtoReader).

I tried changing the enum to int and serializing on server / deserialization works locally. I would like to use an enumeration instead of an int. What am I doing wrong?

Not sure it's relevant information, but an executable file that I run on a server that is built on my local box.

Enumeration refers to reference external dll. When I duplicate the enumeration code in my solution, deserialization works. An exception occurs only when I use an enumeration from an external dll (where I suspect that the source code is unknown), and the enumeration value is larger (it seems) 128. In my case, Status.Zeta and Status. Everyone threw an exception; other enum value deserialized properly. The enumeration is defined as such:

[Flags] public enum Status { None = 0, Alpha = 1, Beta = 8, Gamma = 16, Delta = 32, Epsilon = 64, Zeta = 132, All = 255, } 

I can not change the code in the dll. How can I do this job? Do I need a .proto file? I try to avoid this if possible.

+4
source share
2 answers

This only affects the transfer of which : byte

D'ah! Identify a dead brain error:

 case ProtoTypeCode.SByte: Emit(OpCodes.Conv_Ovf_U1); break; case ProtoTypeCode.Byte: Emit(OpCodes.Conv_Ovf_I1); break; 

It will be canceled and deployed later today. Thanks.

To properly explain: byte has no sign (from 0 to 255), sbyte is signed (-128 to 127); Conv_Ovf_U1 is basically IL to "convert byte , check the Overflow" (for example, how the keyword is checked in C #) and Conv_Ovf_I1 - "convert sbyte , overflow checking." Hence, any value greater than 127 initiated overflow flag, causing the exception. This is fixed in r614, is now expanded.

+3
source

It's really a bit strange. The CLR may be differences that affect ProtoBuf (e.g., CLR supplied with several different GC). Comparing Machine.config files with two machines may reveal some differences.

As for solving the problem, you can try to mark the transfer of ProtoContract themselves and each member of the enumeration with ProtoMember. The latter allows you to set the Value property for ProtoBuf. You can also set DataFormat to Fixed and see if it works better than the default.

The following is an example.

+1
source

All Articles