title: DataContractSerializer, KnownType and inheritance
body: <p>I've read many articles about known types and i belive my example should work. But it doesn't. I'm getting the following exception on deserialization and don't understand why:</p>
  
  <p>Error in line 1 position 2. Expecting element 'A' from namespace '<a href="http://schemas.datacontract.org/2004/07/ConsoleApplication2" rel="noreferrer">http://schemas.datacontract.org/2004/07/ConsoleApplication2</a>'.. Encountered 'Element'  with name 'C', namespace '<a href="http://schemas.datacontract.org/2004/07/ConsoleApplication2" rel="noreferrer">http://schemas.datacontract.org/2004/07/ConsoleApplication2</a>'.</p>
  
  <pre><code>using System;
  using System.Runtime.Serialization;
  using System.Xml;
  using System.IO;
  
  namespace ConsoleApplication2
  {
      [DataContract][KnownType(typeof(C))]class A { }
      [DataContract]class C : A { }
  
      class Program
      {
          static void Main(string[] args)
          {
              A a = new C();
              string data;
  
              var serializer = new DataContractSerializer(a.GetType());
              using (var sw = new StringWriter())
              {
                  using (var xw = new XmlTextWriter(sw))
                      serializer.WriteObject(xw, a);
                  data = sw.ToString();
              }
  
              serializer = new DataContractSerializer(typeof(A));
              using (var sr = new StringReader(data))
              using (var xr = new XmlTextReader(sr))
                  a = (A)serializer.ReadObject(xr);
          }
      }
  }
  </code></pre>
  
  <p>What am i missing?</p>