json.net does not serialize properties from derived class
c#, json.net, serialization
Solution
Yes, you are missing the `[DataContract]` attribute on the derived class. You also need to add `[DataMember]` to any properties or fields that you want serialized, if you haven't already added them. Json.Net was changed in version 5.0 release 1 (April 2013) such that the `[DataContract]` attribute is not inherited.
Note that if you remove all instances of `[DataContract]` and `[DataMemeber]` from your classes, Json.Net behaves differently: in that case, the default behavior is for Json.Net to serialize all public properties, both in the base and derived classes.
Problem
I'm using JSON.NET 6.0.1. When I use the `SerializeObject` method to serialize an object of my derived class, it serializes properties from base class only. Here is the code snippet: ``` string v = JsonConvert.SerializeObject( service, Formatting.Indented, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All }); ``` base class: ``` [DataContract] public abstract partial class DataEntity : IDataEntity, INotifyPropertyChanging, INotifyPropertyChanged { ... } ``` derived class: ``` [Table(Name = "dbo.mytable")] public sealed class mytable : DataEntity { ... } ``` Am I missing something?