c# - XML serialization: class within a class -
i serializing xml, , had working simple class, when made secondary class, of simple class component, serialization stopped working. fails "error reflecting type" error @ serialization stage. code follows:
public class customfield { [xmlattribute("fieldid")] public string fieldid; [xmlattribute("fieldvalue")] public string fieldvalue; public customfield() { } public customfield(string fieldid, string fieldvalue) { this.fieldid = fieldid; this.fieldvalue = fieldvalue; } } [xmltype("entry")] public class customentry { [xmlattribute("author")] public string author; [xmlattribute("title")] public string title; [xmlattribute("trial")] public string trial; [xmlattribute("responses")] public list<customfield> responses; public customentry() { } } public static class entryserializer { public static void serializeobject(this customentry entry, string file) { var serializer = new xmlserializer(typeof(customentry)); using (var stream = file.openwrite(file)) { serializer.serialize(stream, entry); } } }
is labeling issue xml markers, or else?
try defining serializer this:
var serializer = new xmlserializer(typeof(customentry), new type[] { typeof(customfield) });
you need inform serializer of additional types expecting serialize.