Skip to content

Correct FileStream(FileOptions) docs for bufferSize = 0 behavior - #13062

Open
adamsitnik with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-file-stream-documentation
Open

Correct FileStream(FileOptions) docs for bufferSize = 0 behavior#13062
adamsitnik with Copilot wants to merge 5 commits into
mainfrom
copilot/fix-file-stream-documentation

Conversation

Copilot AI commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

The docs for FileStream(string, FileMode, FileAccess, FileShare, int, FileOptions) currently state that bufferSize must be > 0 and that 0 throws. Runtime behavior allows 0 and only rejects negative values.

  • Scope: targeted constructor docs

    • Updated the bufferSize parameter text for the (..., int bufferSize, FileOptions options) overload to allow non-negative values.
    • Documented that bufferSize: 0 disables internal buffering.
  • Exception contract alignment

    • Updated ArgumentOutOfRangeException text for the same overload from “negative or zero” to “negative”.
  • Result

    • Documentation now matches .NET 10 runtime semantics for this overload without changing unrelated constructor entries.
<!-- before -->
<param name="bufferSize">... greater than 0 ...</param>
<exception cref="T:System.ArgumentOutOfRangeException">
  <paramref name="bufferSize" /> is negative or zero.
</exception>

<!-- after -->
<param name="bufferSize">... non-negative ... A value of 0 disables buffering ...</param>
<exception cref="T:System.ArgumentOutOfRangeException">
  <paramref name="bufferSize" /> is negative.
</exception>

Internal previews

File Preview link
xml/System.IO/FileStream.xml Learn preview

Build report

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect documentation for FileStream constructor bufferSize Correct FileStream(FileOptions) docs for bufferSize = 0 behavior Sep 10, 2026
Copilot AI requested a review from adamsitnik September 10, 2026 12:06

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Passing 1 as bufferSize works on every .NET version, but 0 only in .NET 6 and above. Please do capture that in the doc.

Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>

Copilot AI commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Passing 1 as bufferSize works on every .NET version, but 0 only in .NET 6 and above. Please do capture that in the doc.

Updated in cc63e7a. The constructor docs now state that bufferSize = 0 is supported in .NET 6 and later (disables buffering), and that 0 throws in versions earlier than .NET 6.

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot please address my feedback

Comment thread xml/System.IO/FileStream.xml
Comment thread xml/System.IO/FileStream.xml Outdated
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>

Copilot AI commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

@copilot please address my feedback

Addressed in 5abebd3.

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@adamsitnik
adamsitnik requested a review from gewarren September 10, 2026 13:39
@adamsitnik
adamsitnik marked this pull request as ready for review September 10, 2026 13:39
Copilot AI lite review requested due to automatic review settings September 10, 2026 13:39
@adamsitnik
adamsitnik requested a review from a team as a code owner September 10, 2026 13:39
@adamsitnik
adamsitnik enabled auto-merge (squash) September 10, 2026 13:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The updated bufferSize parameter text is potentially misleading for pre-.NET 6 readers because it opens with “non-negative” while the exception contract still disallows 0 in those versions.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates the API reference documentation for FileStream(string, FileMode, FileAccess, FileShare, int bufferSize, FileOptions options) so the bufferSize parameter and related ArgumentOutOfRangeException text better match runtime behavior (notably for bufferSize == 0).

Changes:

  • Updates the bufferSize parameter description to reflect non-negative values and document buffering behavior for 0/1.
  • Refines the ArgumentOutOfRangeException contract to distinguish negative values from the pre-.NET 6 behavior for bufferSize == 0.
File summaries
File Description
xml/System.IO/FileStream.xml Adjusts constructor parameter and exception documentation for bufferSize to align with runtime semantics and version differences.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread xml/System.IO/FileStream.xml Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
<param name="access">A bitwise combination of the enumeration values that determines how the file can be accessed by the <see langword="FileStream" /> object. This also determines the values returned by the <see cref="P:System.IO.FileStream.CanRead" /> and <see cref="P:System.IO.FileStream.CanWrite" /> properties of the <see langword="FileStream" /> object. <see cref="P:System.IO.FileStream.CanSeek" /> is <see langword="true" /> if <paramref name="path" /> specifies a disk file.</param>
<param name="share">A bitwise combination of the enumeration values that determines how the file will be shared by processes.</param>
<param name="bufferSize">A positive <see cref="T:System.Int32" /> value greater than 0 indicating the buffer size. The default buffer size is 4096.</param>
<param name="bufferSize">A non-negative <see cref="T:System.Int32" /> value indicating the buffer size. The default buffer size is 4096. In versions earlier than .NET 6, this value must be greater than 0. In .NET 6 and later versions, a value of 0 disables buffering (a value of 1 disables buffering in every version).</param>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We actually removed all comments for out of support versions. When you say versions earlier than .NET 6, does that apply to .NET Framework as well? If so, let's put that info in the dotnetfw-api-docs repo instead and just state the [.NET 6+] behavior here without a version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileStream constructor documentation incorrectly states that bufferSize: 0 throws

4 participants