ScruffyDuck
ScruffyDuck

Reputation: 2666

How to Fix Enum Error in ProtoBuf-Net

I am getting this error when trying to serialize.

Error Message on Serializing

The answer to this question:

How to map System Enum's in Protobuf.Net

indicates that this is related to a Flags Enum and that it should be handled in V2. The Enum being reported here is not a Flags Enum:

public enum RunwayDesignator {
    NONE = 0,
    LEFT = 1,
    RIGHT = 2,
    CENTER = 3,
    WATER = 4,
    C = 5,
    L = 6,
    R = 7,
    W = 8,
    A = 9,
    B = 10,
    NOT_APP = 99
}

I assume the '16' refers to something in the Enum although there are not 16 values. I checked also to see if there are any ProtoMember IDs of 16 related to unsages of this enum - there are not. All usages of this enum that are serialized are private fields.

I would appreciate some guidance on how to deal with this.

Mant Thanks

Upvotes: 1

Views: 1453

Answers (1)

ScruffyDuck
ScruffyDuck

Reputation: 2666

Well - this is embarrassing. The problem is that the value of 16 is indeed being generated. So it looks like this is some sort of programming error on my part. The error message is saying there is no value for 16 in the enum and that is true.

So I can now go back and try and fix my code. Protobuf-Net is nowhere at fault.

I guess this might be useful for others who see this error. Find out where the enum value is being used and see if the code is sending an invalid value. What I don't understand is why I am not seeing some sort of runtime error when trying to set an invalid index for the enum. I need to investigate that now. And here is an answer to that

Why does casting int to invalid enum value NOT throw exception?

It seems that there is no error generated for invalid enum values but protobuf-net does find them

Upvotes: 1

Related Questions