dotnet-api-docs icon indicating copy to clipboard operation
dotnet-api-docs copied to clipboard

Align MemoryStream Position and Seek docs with SetLength

Open oii-nasif opened this issue 3 months ago • 2 comments

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

oii-nasif avatar Oct 03 '25 23:10 oii-nasif