Stream.Length throws NotSupportedException

前端 未结 6 1878
予麋鹿
予麋鹿 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 16:07

    Stream.Length only works on Stream implementations where seeking is available. You can usually check to see if Stream.CanSeek is true. Many streams, since they're being streamed, are of a nature where it's impossible to know the length in advance.

    If you must know the length, you may need to actually buffer the entire stream, loading it into memory in advance.

提交回复
热议问题