Intermittent problem with XML deserialization

  • Thread starter Michael A. Covington
  • Start date
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?
 
M

Michael A. Covington

Thanks. I think an instrumented build is the way to go. I have never
reproduced the problem; the files look perfectly normal when the user
e-mails them to me; and I'm suspecting there's something weird about the
user's disk i-o situation.

In the latest release of the program I have made the error-checking a bit
more elaborate, but I probably need to go whole hog -- if there's a problem
reading the file in XML, then immediately read it as plain text and write it
in the log, so I can see what the program saw.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top