dotnet/runtime

PipeReader.AdvanceTo throws InvalidCastException

Open

#849 创建于 2019年12月13日

在 GitHub 查看
 (1 评论) (0 反应) (0 负责人)C# (5,445 fork)batch import
area-System.IO.Pipelineshelp wanted

仓库指标

Star
 (17,886 star)
PR 合并指标
 (平均合并 12天 11小时) (30 天内合并 661 个 PR)

描述

I'm puzzled by the fact that PipeReader.AdvanceTo accepts a default(SequencePosition) but throws InvalidCastException when provided a position from an empty sequence. Is that by design?

var pipe = new Pipe();
pipe.Reader.AdvanceTo(default); // this works
pipe.Reader.AdvanceTo(ReadOnlySequence<byte>.Empty.Start); // this throws InvalidCastException

Should it throw ArgumentException instead given the SequencePosition came from an unrelated ReadOnlySequence<byte>?

I'm a bit puzzled that PipeReader.AdvanceTo can be called before reading anyway.

贡献者指南