title: DataContractSerializer, why is "this" not upcasted?
body: <p>I'm working on a server coded with F#. This server connects to a WCF REST service coded with C#.</p>
  
  <p><strong>My F# project is referencing the C# assembly.</strong></p>
  
  <p>In my C# I have <code>namespace GlobalNotificationService.DTO</code>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class Producer
  {
      [DataMember(Name = "Name", IsRequired = true, Order = 1)]
      public string Name {get; set;}
      ...
      public string Marshal()
      {
          StringBuilder sb = new StringBuilder();
          using (XmlTextWriter textWriter = new XmlTextWriter(new StringWriter(sb)))
          {
              DataContractSerializer serializer = new DataContractSerializer(typeof(DTO.Producer));                
              serializer.WriteObject(textWriter, this); //THIS IS THE LINE THROWING THE EXECPTION
              textWriter.Flush();
              textWriter.Close();
              return sb.ToString();
          }
      }
  }
  </code></pre>
  
  <p>In my F# I have <code>namespace ServiceCore</code>:</p>
  
  <pre class="lang-ml prettyprint-override"><code>type Producer(file_name) as this =
      inherit DTO.Producer()
      ...
      member public this.SerializedXML
          with get() = this.Marshal() //Call to C# assembly
  </code></pre>
  
  <p>So the code does compile but I get this exception at run time <em>(look for the comment above)</em>.</p>
  
  <blockquote>
    <p>Type <strong>'ServiceCore.Producer'</strong> with data contract name
    <strong>'Producer:http://schemas.datacontract.org/2004/07/ServiceCore'</strong> is not
    expected. Consider using a DataContractResolver or add any types not
    known statically to the list of known types - for example, by using
    the KnownTypeAttribute attribute or by adding them to the list of
    known types passed to DataContractSerializer.</p>
  </blockquote>
  
  <h2>The question is:</h2>
  
  <p>Why is "this" of type <strong>ServiceCode.Producer</strong> <em>(F#)</em> even though it should have been upcasted to <strong>DTO.Producer</strong> <em>(C#)</em> since the method is in the <strong>DTO.Producer</strong> class and that I'm explicitly asking for a <strong>DTO.Producer</strong> serialization?</p>
  
  <h2>Complementary question:</h2>
  
  <p>Why do we even care about the fact that the call is coming from a descendant class? Our "this" reference should still be up-casted and be of type <strong>DTO.Producer</strong>.</p>
  
  <p>It doesn't make a lot of sence to me, am I missing something?</p>