Stream.Length引发NotSupportedException [英] Stream.Length throws NotSupportedException

查看:2476
本文介绍了Stream.Length引发NotSupportedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我就发到我的WCF方法Stream对象试图stream.Length时,得到一个错误。

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 Warning: False
 Type: System.NotSupportedException
 Stack:    at System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream.get_Length()

你如何获得流的长度是多少?什么例子?

How do you get the length of the stream? any examples?

推荐答案

流.Length 的仅适用于流实现中寻求可用。通常,您可以检查,看看是否 Stream.CanSeek 是真实的。许多溪流,因为他们是的的,是一个性质,这是不可能预先知道的长度。

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.

这篇关于Stream.Length引发NotSupportedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆