EOF Occurs Early

  • Thread starter Thread starter Fred Chateau
  • Start date Start date
F

Fred Chateau

I have an interesting problem with file IO, maybe even a bug in the CLR.

I call a method that uses an XmlReader to loop through 4 MB XML files and
store the text in a database. I select the files in a file select dialog and
loop through the filename array, calling the XmlReader method each time.

If I input one file, everything works properly. If I input several files,
the first file is not read completely. The rest are then processed
correctly. It doesn't matter which file is the first file selected, it
always results in incomplete data from that file. In fact, it always drops
off at the same record each time, about a quarter way through the file.

I checked with the debugger, and when the file hits the record where it
drops out, the XmlReader reports end of file.

Has anyone heard of a similar problem as this? Any ideas how I might fix or
workaround the problem?

I tried adding a FileStream to the XmlReader but it didn't help.
 
I got some more information to go with this.

You can select four files and all files are processed correctly. Seven or
more files causes the first one to drop out early. Does this make sense to
anyone because it doesn't make sense to me? The files are being processed
one at a time, I think. It's just the filenames that are held in an array
until the method is called.
 
I added back the FileStream in order to see more information about the file
in the debugger. When five or more files are selected, the first file shows
a different file size than it actually is.
 
Fred Chateau said:
I added back the FileStream in order to see more information about the file
in the debugger. When five or more files are selected, the first file shows
a different file size than it actually is.

Without seeing any code, it's going to be virtually impossible to get
any further on this.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
I found it. Apparently one of the files (the last file) is shorter than the
rest. What I discovered is that when you load multiple files into the
OpenFileDialog, no matter what order you select them, apparently the dialog
loads them from the smallest file to the largest.

Even though the standard filename sorting order is different, it doesn't
seem to make any difference. In this case, the file was named xxx014.xml and
it loaded before xxx001.xml.

--
Regards,

Fred Chateau
http://hotelmotelnow.com
 

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

Back
Top