I have a class in my C# project marked with the [Serializable]
attribute. It has a property of type RSAKeyValue
:
[XmlElement(PUBLIC_KEY_TAG_NAME)]
public RSAKeyValue Key { get; private set; }
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:
System.InvalidOperationException: System.Security.Cryptography.KeySizes cannot be serialized because it does not have a parameterless constructor.
This occurs when I call XmlSerializer.Serialize
. I'm sure it's because of the RSAKeyValue
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 RSAKeyValue
instance that properly serializes/deserializes?
Here is some sample XML that could be deserialized into an RSAKeyValue
instance:
<RSAKeyValue>
<Modulus>long string here...</Modulus>
<Exponent>short string here</Exponent>
</RSAKeyValue>