Forum Xamarin Cross Platform with Xamarin

DataContractJsonSerializer __type makes deserialization fails

I'm trying to serialize and deserialize JSON data using DataContractJsonSerializer. Everything works perfectly until .NET/Mono decide to add __type field when it writes the object to JSON string. Now when it tries to read the JSON string, it gives system.typeinitializationexception. I would assume that since Mono is the one who adding that extra field, it would be able to read it, but no.

I then tried to stop Mono from generating __type field by using DataContractJsonSerializerSettings.EmitTypeInformation set it to EmitTypeInformation.Never, but that doesn't do anything. Mono still adding that __type field.

Is there a way to get around this? All I want is to be able to write and read the object using DataContractJsonSerializer.

This is how my object looks like,

    public class UserObj {
            public string email { get; set; }
            public string deviceId { get; set; }
            public List<StoreObj> stores { get; set; }


Sign In or Register to comment.