Now I'm trying to serialize a List<InputFile> to XML. I'm using the following code:
Expand|Select|Wrap|Line Numbers
- 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();
Expand|Select|Wrap|Line Numbers
- <?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:
Expand|Select|Wrap|Line Numbers
- 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