Uh oh!
There was an error while loading. Please reload this page.
Remove isAsync flag validation from FileStream constructors - #123761
Conversation
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…ification Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
LGTM (assuming the tests are going to pass).
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. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
adamsitnik
commented
Jan 30, 2026
/ba-g infrastructure timeouts |
slang25
commented
Feb 2, 2026
Perhaps the old constructor should be marked as |
…23761) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
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.