Stream.Length throws NotSupportedException

前端 未结 6 1883
予麋鹿
予麋鹿 2020-12-14 15:30

I am getting a error when attempting stream.Length on a Stream object sent into my WCF method.

Unhandled Exception!
 Error ID: 0
 Error Code: Unknown
 Is War         


        
6条回答
  •  隐瞒了意图╮
    2020-12-14 15:52

    It is not always possible to get the length of a stream if it doesn't support seeking. See the exception table on the Stream class.

    For example, a stream hooked up to another process (network stream, standard output, etc) can produce any amount of output, depending on how the other process is written, and there's no way for the framework to figure out how much data there is.

    In the general case, you just have to read in all of the data until the end of the stream and then figure out how much you've read.

提交回复
热议问题