Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

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.