title: serializing an RSAKeyValue property in Serializable class
body: <p>I have a class in my C# project marked with the <code>[Serializable]</code> attribute.  It has a property of type <a href="http://msdn.microsoft.com/en-us/library/system.security.cryptography.xml.rsakeyvalue.aspx" rel="nofollow noreferrer"><code>RSAKeyValue</code></a>:</p>
  
  <pre><code>[XmlElement(PUBLIC_KEY_TAG_NAME)]
  public RSAKeyValue Key { get; private set; }
  </code></pre>
  
  <p>When I try to serialize an instance of my class to XML and then deserialize that XML back to an instance of my class, I get:</p>
  
  <blockquote>
    <p>System.InvalidOperationException: System.Security.Cryptography.KeySizes cannot be serialized because it does not have a parameterless constructor.</p>
  </blockquote>
  
  <p>This occurs when I call <code>XmlSerializer.Serialize</code>.  I'm sure it's because of the <code>RSAKeyValue</code> property in my class since all the other properties that get serialized are simple strings.  What can I do about this?  Should I maybe make my own wrapper class around an <code>RSAKeyValue</code> instance that properly serializes/deserializes?</p>
  
  <p>Here is some sample XML that could be deserialized into an <code>RSAKeyValue</code> instance:</p>
  
  <pre><code>&lt;RSAKeyValue&gt;
    &lt;Modulus&gt;long string here...&lt;/Modulus&gt;
    &lt;Exponent&gt;short string here&lt;/Exponent&gt;
  &lt;/RSAKeyValue&gt;
  </code></pre>