none
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.

    Thanks,
    Zhihao

    Friday, February 16, 2007 1:16 PM

Answers

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.

    KjellSJ
    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: http://msdn2.microsoft.com/en-us/library/aa347875.aspx

    KjellSJ
    Saturday, February 17, 2007 3:25 PM