Remove isAsync flag validation from FileStream constructors#123761
Merged
adamsitnik merged 5 commits intomainfrom Jan 30, 2026
Merged
Remove isAsync flag validation from FileStream constructors#123761adamsitnik merged 5 commits intomainfrom
adamsitnik merged 5 commits intomainfrom
Conversation
Co-authored-by: adamsitnik <[email protected]>
adamsitnik
reviewed
Jan 29, 2026
Member
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
...aries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_sfh_fa_buffer_async.cs
Outdated
Show resolved
Hide resolved
...aries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_sfh_fa_buffer_async.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: adamsitnik <[email protected]>
Co-authored-by: adamsitnik <[email protected]>
Copilot
AI
changed the title
[WIP] Remove isAsync flag validation from FileStream constructors
Remove isAsync flag validation from FileStream constructors
Jan 29, 2026
…ification Co-authored-by: adamsitnik <[email protected]>
adamsitnik
approved these changes
Jan 29, 2026
Member
adamsitnik
left a comment
There was a problem hiding this comment.
LGTM (assuming the tests are going to pass).
Contributor
There was a problem hiding this comment.
Pull request overview
Removes validation that the isAsync constructor argument must match SafeFileHandle.IsAsync, and updates tests accordingly so FileStream construction uses the handle’s async capability rather than the caller-provided flag.
Changes:
- Updated
FileStreamconstructors to ignore theisAsyncargument and consistently usehandle.IsAsyncwhen selecting the implementation strategy. - Removed now-unused throw helpers and resource strings related to async/sync handle mismatch validation.
- Updated the relevant
FileStreamconstructor test to assert mismatch is allowed and to exercise async read/write behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/libraries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_sfh_fa_buffer_async.cs | Updates the mismatch test to be a theory and verifies behavior/operations when isAsync doesn’t match. |
| src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs | Removes unused throw helpers for async/sync handle mismatch. |
| src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs | Removes isAsync validation and switches strategy selection to use handle.IsAsync. |
| src/libraries/System.Private.CoreLib/src/Resources/Strings.resx | Removes unused resource strings for mismatch validation errors. |
...aries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_sfh_fa_buffer_async.cs
Show resolved
Hide resolved
...aries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_sfh_fa_buffer_async.cs
Show resolved
Hide resolved
...aries/System.Runtime/tests/System.IO.FileSystem.Tests/FileStream/ctor_sfh_fa_buffer_async.cs
Show resolved
Hide resolved
This was referenced Jan 30, 2026
Open
stephentoub
approved these changes
Jan 30, 2026
Member
|
/ba-g infrastructure timeouts |
Contributor
|
Perhaps the old constructor should be marked as |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
FileStream constructors validated that the user-provided
isAsyncparameter matchedSafeFileHandle.IsAsync, throwingArgumentExceptionon mismatch. This validation is removed—constructors now ignore the parameter and always use the handle's actual async state.Changes
handle.IsAsyncto strategy selection, regardless of user-providedisAsyncparameterValidateHandleoverload that checked isAsync mismatchThrowArgumentException_HandleNotAsync/Sync) and resource strings (Arg_HandleNotAsync/Sync)FileStream.IsAsyncreflects handle state, not the ignored parameterUnmatchedAsyncIsAllowedtest to a Theory withInlineDatafor both true and false valuesExample
The
isAsyncparameter becomes effectively unused but remains for API compatibility.Original prompt
FileStreamctors #123760💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.