Search code examples
c#wcfdatacontract

DataContract inheritance not known type


Hi my datacontract has inheritance, but the last member is not accessible when consuming the service:

namespace Services.SearchService
{

    [DataContract]
    [KnownType(typeof(LabellingSearch))]
    public class SearchResult
    {
        [DataMember]
        public int ID { get; set; }

        [DataMember]
        public string Title { get; set; }

        [DataMember]
        public DateTime Modified { get; set; }
    }

    /// <summary>
    /// Specialist Search Result for Labelling Content Data
    /// </summary>
    [DataContract]
    [KnownType(typeof(Labelling))]
    public class LabellingSearch : SearchResult
    {
        [DataMember]
        public string Region { get; set; }

        [DataMember]
        public string Country { get; set; }

        [DataMember]
        public string LabelSummary { get; set; }
    }

    /// <summary>
    /// Full Labelling Content Data
    /// </summary>
    [DataContract]
    public class Labelling : LabellingSearch
    {
        public string Content { get; set; }
   }
}

so in the consuming class I can access the type 'Labelling' but I can't get at its 'Content' property.


Solution

  • You didn't put that member of the class as [DataMember]

    [DataContract]
        public class Labelling : LabellingSearch
        {
            [DataMember]
            public string Content { get; set; }
       }