You can use ExtendedXmlSerializer to serialize and deserialize.
Instalation
You can install ExtendedXmlSerializer from nuget or run the following command:
Install-Package ExtendedXmlSerializer
Serialization:
ExtendedXmlSerializer serializer = new ExtendedXmlSerializer();
var obj = new Message();
var xml = serializer.Serialize(obj);
Deserialization
var obj2 = serializer.Deserialize(xml);
Standard XML Serializer in .NET is very limited.
- Does not support serialization of class with circular reference or class with interface property,
- Does not support Dictionaries,
- There is no mechanism for reading the old version of XML,
- If you want create custom serializer, your class must inherit from IXmlSerializable. This means that your class will not be a POCO class,
- Does not support IoC.
ExtendedXmlSerializer can do this and much more.
ExtendedXmlSerializer support .NET 4.5 or higher and .NET Core. You can integrate it with WebApi and AspCore.