I have several classes that are immutable once their initial values are set. Eric Lippert calls this write-once immutability.
Implementing write-once immutability in C# usually means setting the initial values via the constructor. These values initialize readonly fields.
But if you need to serialize a class like this to XML, using either the XmlSerializer or the DataContractSerializer, you must have a parameterless constructor.
Does anyone have suggestions for how to work around this problem? Are there other forms of immutability that work better with serialization?
EDIT: As @Todd pointed out, the DataContractSerializer does not require a parameterless constructor. According to the DataContractSerializer documentation on MSDN, DataContractSerializer "does not call the constructor of the target object."