ReadTimeout threw an exception when converting byte array to Stream

前端 未结 4 712
独厮守ぢ
独厮守ぢ 2021-01-20 06:33

I got this error

ReadTimeout = \'((System.IO.Stream)(ms)).ReadTimeout\' threw an exception of type \'System.InvalidOperationException\'.

M

4条回答
  •  半阙折子戏
    2021-01-20 07:13

    The ReadTimeout property must be overridden, in the base System.IO.Stream class it always throw System.InvalidOperationException error by design.

    The solution is not to cast ms to the base type when reading the timeout:

    int readTimeout = ms.ReadTimeout;
    

    Edit: didn't check before posting.. MemoryStream also does not override that property - meaning timeout for such stream is not implemented.

    You have to either use other implementation of Stream class that does override the ReadTimeout property, or write your own implementation.

提交回复
热议问题