Skip to content

Remove isAsync flag validation from FileStream ctors #123760

Closed

Description

@adamsitnik

For the historical reasons described here, .NET was so far throwing if the value of isAsync boolean flag did not match the value returned by SafeFileHandle.IsAsync.

We have agreed to remove these checks:

if (isAsync && !handle.IsAsync)
{
ThrowHelper.ThrowArgumentException_HandleNotAsync(nameof(handle));
}
else if (!isAsync && handle.IsAsync)
{
ThrowHelper.ThrowArgumentException_HandleNotSync(nameof(handle));
}

And simply pass the actual value of handle.IsAsync to the layer that chooses the right strategy, just like we do when the flag was not provided by the user:

_strategy = FileStreamHelpers.ChooseStrategy(this, handle, access, bufferSize, handle.IsAsync);

So the following lines need to be updated:

_strategy = FileStreamHelpers.ChooseStrategy(this, handle, access, bufferSize, isAsync);

_strategy = FileStreamHelpers.ChooseStrategy(this, safeHandle, access, bufferSize, isAsync);

And all unused code (like the throw helpers) needs to be removed as well. The tests also need to be updated accordingly.

Activity

  1. added this to the 11.0.0 milestone on Jan 29, 2026
  2. dotnet-policy-service commented on Jan 29, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @dotnet/area-system-io
    See info in area-owners.md if you want to be subscribed.

  3. locked and limited conversation to collaborators on Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions