Stream.Length throws NotSupportedException(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?
推荐答案
Stream.Length 仅适用于可以进行查找的 Stream 实现.您通常可以检查 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Stream.Length 抛出 NotSupportedException


基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01