dotnet/runtime

PipeReader.AdvanceTo throws InvalidCastException

開放

#849 建立於 2019年12月13日

 (1 則留言) (0 個反應) (0 位負責人)C# (5,445 個分叉)batch import
area-System.IO.Pipelineshelp wanted

倉庫指標

星標
 (17,886 顆星)
PR 合併指標
 (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.

貢獻者指南