I use XMLSerializer to save this class to a file. The class has a string and an enumeration, as shown below:
public class IOPoint { string Name {get; set;} TypeEnum {get; set;} } public enum TypeEnum { Temperature, Pressure, Humidity, }
When serialized, it looks like this.
<IOPoint> <Name>Relative Humidity</Name> <TypeEnum>Humidity</TypeEnum> </IOPoint>
I serialize and deserialize this object without problems for multiple versions. I no longer want to maintain Humidity, so I removed it from the listing. However, this throws an exception when deserializing from XML, because the value in the TypeEnum field, Humidity, is not a valid value for TypeEnum. It makes sense, but how to handle it?
What I would like to do is simply ignore this error. And leave the value equal to zero. I tried to implement the OnUnknownElement XmlDeserilizationEvent class. Unfortunately, this does not resolve this error.
Any ideas on how to catch and ignore this error (I can clear it after deserialization is complete).
Mitch
c # xml serialization versioning deserialization
Mitch
source share