The server encountered an error processing the request error

Error: The server encountered an error processing the request. The exception message is 'Invalid enum value 'Public' cannot be deserialized into type 'NAMESPACE.CLASSES.ENUMTYPE'. Ensure that the necessary enum values are present and are marked with EnumMemberAttribute attribute if the type has DataContractAttribute attribute.'. See server logs for more details. The exception stack trace is:

This issue occurs whenever we don't add certain attribute to ENUM defined in our WCF services.

Let's take below ENUM implementation, which we usually define as follows.

    [DataContract]
    public enum CompType
    {

       Public=0,
       Private=1,
       Agency=2
    }

So to over this issue we need to modify our enum implementation as follows

    [DataContract]
    [Flags]
    public enum CompType
    {
        [EnumMember]
        Public=0,
        [EnumMember]
        Private=1,
        [EnumMember]
        agency=2
    }

Happy coding... Hope this helps!

Ebook Download
View all
Learn
View all