gpt4 book ai didi

c# - Stream.Length 抛出 NotSupportedException

转载 作者:IT王子 更新时间:2023-10-29 04:15:49 24 4
gpt4 key购买 nike

尝试对发送到我的 WCF 方法的 Stream 对象进行 stream.Length 时出现错误。

Unhandled Exception!
Error ID: 0
Error Code: Unknown
Is Warning: False
Type: System.NotSupportedException
Stack: at System.ServiceModel.Dispatcher.StreamFormatter.MessageBodyStream.get_Length()

如何获取流的长度?有什么例子吗?

最佳答案

Stream.Length仅适用于可以搜索的 Stream 实现。您通常可以查看是否 Stream.CanSeek是真的。许多流,因为它们是流式传输,所以无法提前知道长度。

如果您必须知道长度,您可能需要实际缓冲整个流,提前将其加载到内存中。

关于c# - Stream.Length 抛出 NotSupportedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3373579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com