M
Michael A. Covington
A few of the users of my program are encountering an XmlException that looks
as if the XmlSerializer is seeing an empty file (error at line 0, position
0, root element missing).
I have a hunch the problem is that I was doing this:
StreamReader r = new StreamReader(filename);
XmlSerializer x = new XmlSerializer(...the type...);
....my object... = x.Deserialize(r);
when I should have been doing this:
TextReader r = new StreamReader(filename);
XmlSerializer x = new XmlSerializer(...the type...);
....my object... = x.Deserialize(r);
The documentation shows deserialization from a TextReader and from a Stream
but not from a StreamReader. Nonetheless, StreamReader worked 99.99% of the
time, and I have not been able to isolate the conditions under which people
were seeing an apparently empty file. They saw it very reproducibly, but
the same file, e-mailed to me and opened with the same program, worked
perfectly.
Am I following the right scent? What else could it be?
as if the XmlSerializer is seeing an empty file (error at line 0, position
0, root element missing).
I have a hunch the problem is that I was doing this:
StreamReader r = new StreamReader(filename);
XmlSerializer x = new XmlSerializer(...the type...);
....my object... = x.Deserialize(r);
when I should have been doing this:
TextReader r = new StreamReader(filename);
XmlSerializer x = new XmlSerializer(...the type...);
....my object... = x.Deserialize(r);
The documentation shows deserialization from a TextReader and from a Stream
but not from a StreamReader. Nonetheless, StreamReader worked 99.99% of the
time, and I have not been able to isolate the conditions under which people
were seeing an apparently empty file. They saw it very reproducibly, but
the same file, e-mailed to me and opened with the same program, worked
perfectly.
Am I following the right scent? What else could it be?