Skip to content

ROSequence should throw a more helpful exception on a bad slice. #42978

Closed
@Kuinox

Description

@Kuinox

Description

This code:

ReadOnlySequence<byte> bufferA = new ReadOnlySequence<byte>( new byte[50] );
ReadOnlySequence<byte> bufferB = new ReadOnlySequence<byte>( new byte[45] );
ReadOnlySequence<byte> slice = bufferA.Slice( bufferB.End );
long test = slice.Length;

Throws on the last line:

System.InvalidCastException: 'Unable to cast object of type 'System.Byte[]' to type 'System.Buffers.ReadOnlySequenceSegment`1[System.Byte]'.'

As discussed in #766, this behavior is expected, but:

Discussed this with @tannergooding on discord.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions