title: Serializing private member data
body: <p>I'm trying to serialize an object to XML that has a number of properties, some of which are readonly.</p>
  
  <pre><code>public Guid Id { get; private set; }
  </code></pre>
  
  <p>I have marked the class [Serializable] and I have implemented the ISerializable interface.</p>
  
  <p>Below is the code I'm using to serialize my object.</p>
  
  <pre><code>public void SaveMyObject(MyObject obj)
  {
      XmlSerializer serializer = new XmlSerializer(typeof(MyObject));
      TextWriter tw = new StreamWriter(_location);
      serializer.Serialize(tw, obj);
      tw.Close();
  }
  </code></pre>
  
  <p>Unfortunately it falls over on the first line with this message.</p>
  
  <blockquote>
    <p>InvalidOperationException was unhandled:
    Unable to generate a temporary class (result=1).
    error CS0200: Property or indexer 'MyObject.Id' cannot be assigned to -- it is read only</p>
  </blockquote>
  
  <p>If I set the Id property to public it works fine. Can someone tell me if I'm doing something, or at least if its even possible?</p>