dotnet / dotnet/dotnet-api-docs

Align MemoryStream Position and Seek to mention origin on ArgumentOutOfRangeException

Open
#9,201 2 comments 1 reaction 0 assignees View on GitHub
area-System.IO help wanted Pri3
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

MemoryStream was recently fixed to avoid falling into a state where it could contain a negative `Position` https://github.com/dotnet/runtime/pull/88572.

Some API docs don't mention the `origin` when they talk about ArgumentOutOfRangeException and only mention that the value must be between int.MaxValue and zero.
* [Seek()](https://learn.microsoft.com/en-us/dotnet/api/system.io.memorystream.seek?view=net-7.0#exceptions)
* [Position](https://learn.microsoft.com/en-us/dotnet/api/system.io.memorystream.position?view=net-7.0#exceptions)

[SetLength](https://learn.microsoft.com/en-us/dotnet/api/system.io.memorystream.setlength?view=net-7.0) does correctly reflect that the limit accounts for the origin:
> value is negative or is greater than the maximum length of the MemoryStream, where the maximum length is (Int32.MaxValue - origin), and origin is the index into the underlying buffer at which the stream starts.

We need to amend the former cases to align with SetLength's.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.