title: WCF Serialization UnitTests and This XmlWriter does not support base64 encoded data. What Writer should I use?
body: <p>I'm writing some unit tests that serialize and deserialize all of our types that might cross the WCF boundary, in order to prove that all properties will make it to the other side.</p>
  
  <p>I've hit a bit of a snag with a byte[] property.</p>
  
  <pre><code>[DataContract(IsReference=true)]
  public class BinaryDataObject
  {
      [DataMember]
      public byte[] Data { get; set; }
  }
  </code></pre>
  
  <p>When I run this object through the testing, I get System.NotSupportedException: <code>This XmlWriter does not support base64 encoded data</code>.</p>
  
  <p>Here's my Serialization method:</p>
  
  <pre><code>public static XDocument Serialize(object source)
  {
    XDocument target = new XDocument();
    using (System.Xml.XmlWriter writer = target.CreateWriter())
    {
      DataContractSerializer s = new DataContractSerializer(source.GetType());
      s.WriteObject(writer, source);
    }
    return target;
  }
  </code></pre>
  
  <p>It occurs to me that my serialization method must be flawed - WCF probably doesn't use <code>XDocument</code> instances and might not use <code>System.Xml.XmlWriter</code> instances.</p>
  
  <p>What Writer does WCF use by default?  I'd like to use instances of that type in my test.</p>