Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,6 @@
<data name="Arg_GuidArrayCtor" xml:space="preserve">
<value>Byte array for Guid must be exactly {0} bytes long.</value>
</data>
<data name="Arg_HandleNotAsync" xml:space="preserve">
<value>Handle does not support asynchronous operations. The parameters to the FileStream constructor may need to be changed to indicate that the handle was opened synchronously (that is, it was not opened for overlapped I/O).</value>
</data>
<data name="Arg_HandleNotSync" xml:space="preserve">
<value>Handle does not support synchronous operations. The parameters to the FileStream constructor may need to be changed to indicate that the handle was opened asynchronously (that is, it was opened explicitly for overlapped I/O).</value>
</data>
<data name="Arg_HexBinaryStylesNotSupported" xml:space="preserve">
<value>The number styles AllowHexSpecifier and AllowBinarySpecifier are not supported on floating point data types.</value>
</data>
Expand Down
13 changes: 2 additions & 11 deletions src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public FileStream(IntPtr handle, FileAccess access, bool ownsHandle, int bufferS
{
ValidateHandle(safeHandle, access, bufferSize, isAsync);

_strategy = FileStreamHelpers.ChooseStrategy(this, safeHandle, access, bufferSize, isAsync);
_strategy = FileStreamHelpers.ChooseStrategy(this, safeHandle, access, bufferSize, safeHandle.IsAsync);
}
catch
{
Expand Down Expand Up @@ -87,15 +87,6 @@ private static void ValidateHandle(SafeFileHandle handle, FileAccess access, int
private static void ValidateHandle(SafeFileHandle handle, FileAccess access, int bufferSize, bool isAsync)
{
ValidateHandle(handle, access, bufferSize);

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

public FileStream(SafeFileHandle handle, FileAccess access)
Expand All @@ -114,7 +105,7 @@ public FileStream(SafeFileHandle handle, FileAccess access, int bufferSize, bool
{
ValidateHandle(handle, access, bufferSize, isAsync);

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

public FileStream(string path, FileMode mode)
Expand Down
12 changes: 0 additions & 12 deletions src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,18 +335,6 @@ internal static void ThrowArgumentException(ExceptionResource resource, Exceptio
throw GetArgumentException(resource, argument);
}

[DoesNotReturn]
internal static void ThrowArgumentException_HandleNotSync(string paramName)
{
throw new ArgumentException(SR.Arg_HandleNotSync, paramName);
}

[DoesNotReturn]
internal static void ThrowArgumentException_HandleNotAsync(string paramName)
{
throw new ArgumentException(SR.Arg_HandleNotAsync, paramName);
}

[DoesNotReturn]
internal static void ThrowArgumentNullException(ExceptionArgument argument)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,20 @@ public void MatchedAsync()
}

[Fact]
public void UnmatchedAsyncThrows()
public void UnmatchedAsyncIsAllowed()
{
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, 4096, true))
{
Assert.Throws<ArgumentException>(() => CreateFileStream(fs.SafeFileHandle, FileAccess.ReadWrite, 4096, false));
// isAsync parameter is now ignored, handle.IsAsync is used instead
using (CreateFileStream(fs.SafeFileHandle, FileAccess.ReadWrite, 4096, false))
{ }
}

using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite | FileShare.Delete, 4096, false))
{
Assert.Throws<ArgumentException>(() => CreateFileStream(fs.SafeFileHandle, FileAccess.ReadWrite, 4096, true));
// isAsync parameter is now ignored, handle.IsAsync is used instead
using (CreateFileStream(fs.SafeFileHandle, FileAccess.ReadWrite, 4096, true))
{ }
}
}
}
Expand Down