Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

<Class> is not registered in this resolver(EnumUnderlyingValueResolver). An exception occurs while serializing an enum as number #239

Open
armanzakinyan opened this issue Dec 4, 2020 · 0 comments

Comments

@armanzakinyan
Copy link

I have these classes below.

[DataContract]
public class Physics
{
    [DataMember]
    public string Lecturer { get; set; }

    [DataMember]
    public WeekDays WeekDay { get; set; }
}

[DataContract]
public enum WeekDays : byte
{
    [EnumMember]
    Monday = 1,

    [EnumMember]
    Tuesday,

    [EnumMember]
    Wednesday,

    [EnumMember]
    Thursday,

    [EnumMember]
    Friday,

    [EnumMember]
    Saturday,

    [EnumMember]
    Sunday
}


Here is my Main() method.

static void Main(string[] args)
    {
        Physics physics_1 = new Physics { Lecturer = "Andrew", WeekDay = WeekDays.Monday };
        var v1 = JsonSerializer.Serialize(physics_1, EnumResolver.UnderlyingValue);
        Console.WriteLine(Encoding.UTF8.GetString(v1));
    }


I want to serialize a Physics object and also I want an enum member of Physics to be a number. While using EnumResolver.UnderlyingValue I got this `exception.`
Physics is not registered in this resolver. resolver:EnumUnderlyingValueResolver
@armanzakinyan armanzakinyan changed the title <Class> is not registered in this resolver. An exception occurs while serializing an enum as number <Class> is not registered in this resolver(resolver:EnumUnderlyingValueResolver). An exception occurs while serializing an enum as number Dec 4, 2020
@armanzakinyan armanzakinyan changed the title <Class> is not registered in this resolver(resolver:EnumUnderlyingValueResolver). An exception occurs while serializing an enum as number <Class> is not registered in this resolver(EnumUnderlyingValueResolver). An exception occurs while serializing an enum as number Dec 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant