简体   繁体   中英

DataContractSerializer not serializing one property

When I serialize the following class, the ContentPageId XML element is missing from the resulting XML file.

[CollectionDataContract(ItemName = "Widget")]
public sealed class StructurePage : List<Widget>, IEquatable<StructurePage>
{
    [DataMember]
    public int ContentPageId
    {
        get;
        set;
    }

    public StructurePage(){}

    public StructurePage(int pageId)
    {
        this.ContentPageId = pageId;
    }

    public bool Equals(StructurePage other)
    {
        return this.ContentPageId.Equals(other.ContentPageId);
    }
}
  1. Why is the property skipped when serializing and how to include it as XML element?
  2. Is it possible to include it in serialization as an XML attribute to the StructurePage element? Was looking for this around the net but could find any info on it, apparently with XmlSerializer there was XmlAttributeAttribute attribute but no such thing with DataContractSerializer.

Go through this post http://social.msdn.microsoft.com/Forums/eu/wcf/thread/57eb195a-43a9-47fe-8b1a-a9d23feb2df2

According to this

Collection data contract classes cannot contain extra data members.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM