WCF Invalid enum value '1' cannot be deserialized into type

390 Views Asked by At

I have a WCF Service having an Enum:-

 [DataContract(Name = "PurchaseType")]
 public enum PurchaseType
 {
    [EnumMember]
    Hire Purchase= 0,
    [EnumMember]
    PCP = 1
 }

DataContract as below:-

[DataContract]
public class Purchase
{
    [DataMember(Order = 3, IsRequired = true, EmitDefaultValue = false)]
    public PurchaseType Type{ get; set; }
}

The enum members have been marked with the "EnumMember" attribute as required - how when I call the method and pass in "1" - I get below error, this should work...

Any pointers appreicated...

1

There are 1 best solutions below

0
Jiayao On

You may add the flags to DataContract like this:

[DataContract] [Flags]

You can check out this document for more information.