- There is currently a limitation to the parameters you can pass to the DataContract and DataMember attributes. In fact, you can use the DataContract and DataMember attributes normally, but if you need to specify some additional properties, such as the Name in [DataContract(Name="TheName")], it will not work because JSIL is currently unable to retain those properties (it only retains the constructor parameters of the attributes). Therefore, instead, you need to use the "DataContract2" and "DataMember2" classes, and pass the parameters to their constructor, like this: [DataContract2(TheName: "TheName")]. Notice that we use the colons (":") instead of the equal sign ("=") because we are passing constructor named arguments instead of directly setting the properties of the attribute. We are working to fix this limitation. If you need more information, please contact us.



Please use the following code to serialize an object with the DataContractSerializer:

var dataContractSerializer = new DataContractSerializer(typeof(ClassToSerialize));
var xml = dataContractSerializer.SerializeToString(_instanceToSerialize);

Please use the following code to deserialize an object with the XmlSerializer:

var dataContractSerializer = new DataContractSerializer(typeof(Person));
ClassToSerialize deserializedObject = (ClassToSerialize)dataContractSerializer.DeserializeFromString(xml);


Full example:

public class Person
    public void Init()
        this.FullName = "John Doe";
        this.Age = 30;
        this.MailingAddress = "";
        this.TelephoneNumber = "0123456789";

    // This member is serialized.
    internal string FullName;

    // This is serialized even though it is private.
    private int Age;

    // This is not serialized because the DataMemberAttribute 
    // has not been applied.
    private string MailingAddress;

    // This is not serialized, but the property is.
    private string telephoneNumberValue;

    public string TelephoneNumber
        get { return telephoneNumberValue; }
        set { telephoneNumberValue = value; }

public void Serialize()
    var person = new Person();

    var dataContractSerializer = new DataContractSerializer(typeof(Person));
    var xml = dataContractSerializer.SerializeToString(person);

public void Deserialize()
    string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
<Person xmlns="""" xmlns:i="""">
<FullName>John Doe</FullName>
    var dataContractSerializer = new DataContractSerializer(typeof(Person));
    var person = (Person)dataContractSerializer.DeserializeFromString(xml);
    MessageBox.Show("Person name: " + person.FullName + Environment.NewLine + "Person phone number: " + person.TelephoneNumber);



For any question, please post a message on the forums or contact us at