have an object (InputFile) that I am able to successfully serialize to XML and deserialize back into the object through an IXmlSerializabl e interface.
Now I'm trying to serialize a List<InputFile> to XML. I'm using the following code:
This produces the following XML:
This looks well formed and good to me.
I use the following to deserialize:
I get an exception on the Deserialize line:
InvalidOperatio nException: {"There is an error in XML document (2, 2)."}
{"<ArrayOfInput File xmlns=''> was not expected."}
I've had no issues Serializing/Deserializing List<>s before.
I've tried variations on providing a fake-namespace or removing the namespace portion altogether. Either way I get an InvalidOperatio nException: {"There is an error in XML document (2, 2)."} (2,2 cooresponds to the A in ArrayOfInputFil e): {"<ArrayOfInput File xmlns=''> was not expected."}
Any ideas where I went wrong?
Thanks
Now I'm trying to serialize a List<InputFile> to XML. I'm using the following code:
Code:
XmlSerializer s = new XmlSerializer(typeof(List<Inputs.InputFile>)); TextWriter w = new StreamWriter("c:\\out.xml"); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("", ""); w.Serialize(w, Global.Pool.InputFiles, ns); w.Close();
Code:
<?xml version="1.0" encoding="utf-8"?> <ArrayOfInputFile> <InputFile FileName="file1.hdr" GUID="XYZ" TimeShift="0"> //objects from a list in the InputFile list </InputFile> <InputFile FileName="file2.hdr" GUID="ABC" TimeShift="0"> //objects from a list in the InputFile list </InputFile> </ArrayOfInputFile>
I use the following to deserialize:
Code:
XmlSerializer s = new XmlSerializer(typeof(Inputs.InputFile)); TextReader r = new StreamReader("c:\\out.xml"); List<Inputs.InputFile> a = (List<Inputs.InputFile>)s.Deserialize(r); r.Close();
InvalidOperatio nException: {"There is an error in XML document (2, 2)."}
{"<ArrayOfInput File xmlns=''> was not expected."}
I've had no issues Serializing/Deserializing List<>s before.
I've tried variations on providing a fake-namespace or removing the namespace portion altogether. Either way I get an InvalidOperatio nException: {"There is an error in XML document (2, 2)."} (2,2 cooresponds to the A in ArrayOfInputFil e): {"<ArrayOfInput File xmlns=''> was not expected."}
Any ideas where I went wrong?
Thanks
Comment