Skip to content

Conversation

oii-nasif
Copy link
Contributor

Summary

  • Updated ArgumentOutOfRangeException documentation for MemoryStream.Position property and MemoryStream.Seek
    method
  • Aligned exception descriptions with the more detailed explanation used in SetLength method
  • Added clarification about how the origin parameter affects the maximum valid position/offset

Details

The SetLength method already included a precise explanation of the ArgumentOutOfRangeException that mentions
the origin parameter:

where the maximum length is (Int32.MaxValue - origin), and origin is the index into the underlying buffer at
which the stream starts.

However, the Position property and Seek method only mentioned Int32.MaxValue without explaining how the
origin affects the valid range.

Changes Made

Position property - Updated from:

The position is set to a negative value or a value greater than Int32.MaxValue.

To:

The position is set to a negative value or a value 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.

Seek method - Updated from:

offset is greater than Int32.MaxValue.

To:

offset 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.

This provides developers with consistent and more accurate information about the actual constraints when working
with MemoryStream instances that may have been initialized with a non-zero origin offset.

Fixes #9201

 Updated ArgumentOutOfRangeException documentation for Position
  property and Seek method to include the more precise explanation
  about the maximum length calculation that accounts for the origin
  parameter.

  Both now match the detailed description in SetLength, specifying
  that the maximum length is (Int32.MaxValue - origin), where origin
  is the index into the underlying buffer at which the stream starts.

  Fixes dotnet#9201
@oii-nasif oii-nasif requested a review from a team as a code owner October 3, 2025 23:53
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 3, 2025
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 3, 2025
@dotnet-policy-service dotnet-policy-service bot removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 6, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-io

@oii-nasif
Copy link
Contributor Author

Hello @gewarren , Have you had a chance to review my changes yet?

@jamesdayo080-cell jamesdayo080-cell mentioned this pull request Oct 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Align MemoryStream Position and Seek to mention origin on ArgumentOutOfRangeException
2 participants