I do not believe that there is an easy way to debug serialization, but there really is no magic: serialization is a simple process, and you can do it yourself.
For recording, I use Serializer DataContract.
Here is the Serialize / Deserialize code
public static string Serialize(object obj) { using(MemoryStream memoryStream = new MemoryStream()) using(StreamReader reader = new StreamReader(memoryStream)) { DataContractSerializer serializer = new DataContractSerializer(obj.GetType()); serializer.WriteObject(memoryStream, obj); memoryStream.Position = 0; return reader.ReadToEnd(); } } public static object Deserialize(string xml, Type toType) { using(Stream stream = new MemoryStream()) { byte[] data = System.Text.Encoding.UTF8.GetBytes(xml); stream.Write(data, 0, data.Length); stream.Position = 0; DataContractSerializer deserializer = new DataContractSerializer(toType); return deserializer.ReadObject(stream); } }
he sometimes skips some properties
Basically, if something is wrong during the Serialization process, the serializer will throw a SerializationException (with detailed information). In your case (the property is still empty or equal by default), it looks like you forgot some attributes.
Well, it’s not easy for you to help you a bit more without any part of the code, but just be aware of the functions of the datacontractserializer (see here ),
Especially when I send a list of custom objects by cable. This returns values for one object all the time.
Try playing it and write unit test for this. There are no random errors, but just very specific scenarios leading to errors.
source share