Share via

Why does BinaryReader.ReadByte() throw NotImplementedException?

Hong 1,526 Reputation points
2023-05-28T01:47:24.1133333+00:00
using (Stream stream = await storageFile.OpenStreamForReadAsync())
{
    BinaryReader br = new BinaryReader(stream);
    List<byte> list = new List<byte>();
    try
    {
        while (true)
        {
            list.Add(br.ReadByte());
        }
    }
    catch (NotImplementedException)
    {

    }
}



The above code works fine most of the time. Occasionally, br.ReadByte() in the above code throws the exception:

System.NotImplementedException: The method or operation is not implemented.
 Stack Trace:
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x21
   at System.IO.StreamOperationAsyncResult.ThrowWithIOExceptionDispatchInfo(Exception) + 0x31
   at System.IO.StreamOperationAsyncResult.ProcessCompletedOperation() + 0x109
   at System.IO.WinRtToNetFxStreamAdapter.EndRead(IAsyncResult) + 0x10d
   at System.IO.WinRtToNetFxStreamAdapter.Read(Byte[], Int32, Int32) + 0x2b
   at SharedLibrary!<BaseAddress>+0xb91583
   at System.IO.BufferedStream.ReadByte() + 0x11
   at System.IO.BinaryReader.ReadByte() + 0x16



Could anyone shed some light on the possible cause?

I want to emphasize this is rare, so it is not a serious problem. I am asking out of curiosity.

Developer technologies | Universal Windows Platform (UWP)

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.