When the class is serialized and the file is saved, an error sometimes occurs when the serialized output looks like this:
<?xml version="1.0"?> <Template xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Route>Some Route</Route> <TradePack>Something Here</TradePack> <Transport /> </Template>te> ------> Notice this extra string?
The serialization of the class I is as follows:
[Serializable] public class Template { public string Route = string.Empty; public string TradePack = string.Empty; public string Transport = string.Empty; public Template() { } }
I canβt understand why this is happening. Here is my serializer class:
public static bool Save(object obj, string path) { try { XmlSerializer writer = new XmlSerializer(obj.GetType()); using (var stream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite)) { writer.Serialize(stream, obj); } return true; } catch { } return false; }
Thanks!
source share