dotnet/runtime

PipeReader.AdvanceTo throws InvalidCastException

Open

#849 opened on 2019年12月13日

GitHub で見る
 (1 comment) (0 reactions) (0 assignees)C# (5,445 forks)batch import
area-System.IO.Pipelineshelp wanted

Repository metrics

Stars
 (17,886 stars)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

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.

コントリビューターガイド