enum type RRS feed

  • Question

  • Hi,

      I have a enum type:
      public enum Test
           Effective = 1,
           NotYetEffective = 2

      Call(Effective | NotYetEffective )
      it will throw exception:
    Enum value '3' is invalid for type 'Test' and cannot be serialized. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.


    Friday, February 16, 2007 1:16 PM


All replies

  • You need to define all the enum items explicitly, and 3 is not an EnumMember in your enum definition. Note that it is the actual enum item name that gets sent over the wire (serialized), not the internal .NET integer key.

    Friday, February 16, 2007 3:24 PM
  • You can solve this by adding the [Flags] attribute to your enum declaration.
    Friday, February 16, 2007 7:23 PM
  • Carlos is right; see details and rules here:

    Saturday, February 17, 2007 3:25 PM