title: protobuf-net using base class instead of derived class when generic class in inheritance chain
body: <p>We are using protobuf-net for serialization with WCF services on the following classes.</p>
  
  <pre><code>[DataContract]
  [KnownType(typeof(NamedViewModel))]
  public class NamedViewModel&lt;TKey&gt; : IViewModel
  {
      [DataMember]
      public virtual TKey Id { get; set; }
  
      [DataMember]
      public virtual string Name { get; set; }
  }
  
  [DataContract]
  [KnownType(typeof(ScheduleTemplateViewModel))]
  public class NamedViewModel : NamedViewModel&lt;int&gt;
  {
  }
  
  [DataContract]
  public class ScheduleTemplateViewModel : NamedViewModel
  {
      [DataMember]
      public string Comment { get; set; }
  }
  </code></pre>
  
  <p>We have a custom routine that basically does (simplified for brevity).</p>
  
  <pre><code>type.GetAttributes&lt;KnownTypeAttribute&gt;().Select(a =&gt; a.Type).Distinct().ForEach(t =&gt; AddKnownTypeHierarchy(t));  
  
  public static void AddKnownTypeHierarchy(Type type)
  {
  
      ProtoBuf.Meta.MetaType metaType = RuntimeTypeModel.Default.Add(type, true);
      ...
      metaType.AddSubType( ...
      ...
  }
  </code></pre>
  
  <p>We are getting the following error on the WCF services.</p>
  
  <pre><code>{"Unable to cast object of type 'Castle.Proxies.NamedViewModel`1Proxy' to type 'Presentation.ViewModels.ScheduleTemplateBuilder.ScheduleTemplateViewModel'."}
  </code></pre>
  
  <p>How can this issue be resolved? </p>
  
  <p>Thanks in advance.</p>