Windows 8 Release Preview – to boldly go where…

6/12/2012 By Marco Kesseler 0 comments

Windows 8 continues to amaze me. I recently upgraded to the Windows 8 Release Preview and tried to run one of our projects. After dealing with some of the changes, it returned an error that I could not quite place.

Debugging revealed that stream.ReadByte() would sometimes leave the stream position far beyond the end of the stream. This only happened in combination with a call to stream.Seek().

So, I wrote the following test. It opens a file, and then tries to seek increasingly further in it – but not beyond the end - and at all these positions it reads a single byte. As soon as this leads to a position beyond the end of the stream, it prints how far from the end of the stream we were actually trying to read.

1 var file = await fileOpenPicker.PickSingleFileAsync() 2 if (file != null) 3 { 4 Stream stream = await file.OpenStreamForReadAsync(); 5 for (long i = 0; i < stream.Length; i++) 6 { 7 stream.Seek(i, SeekOrigin.Begin); 8 if (stream.ReadByte() >= 0) 9 { 10 if (stream.Position >= stream.Length) 11 { 12 System.Diagnostics.Debug.WriteLine(stream.Length - i); 13 } 14 } 15 } 16 }

And the result is: things start to go wrong at 8192 bytes before the end of the stream. For every file I tested. Always.

Now I am starting to become a bit paranoid. Is it just me? Am I doing something wrong? Is my metro system hosed? I have Googled for this issue, but found nothing. Am I the only one trying to do these things on Windows 8? I cannot believe it.