Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions docs/project/list-of-diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ The PR that reveals the implementation of the `<IncludeInternalObsoleteAttribute
| __`SYSLIB0060`__ | The constructors on Rfc2898DeriveBytes are obsolete. Use the static Pbkdf2 method instead. |
| __`SYSLIB0061`__ | The Queryable MinBy and MaxBy taking an IComparer\<TSource\> are obsolete. Use the new ones that take an IComparer\<TKey\>. |
| __`SYSLIB0062`__ | XSLT Script blocks are not supported. |
| __`SYSLIB0063`__ | This constructor has been deprecated and argument bool isConnected does not have any effect. Use NamedPipeClientStream(PipeDirection direction, bool isAsync, SafePipeHandle safePipeHandle) instead. |

## Analyzer Warnings

Expand Down
3 changes: 3 additions & 0 deletions src/libraries/Common/src/System/Obsoletions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ internal static class Obsoletions
internal const string XsltSettingsEnableScriptMessage = "XSLT Script blocks are not supported.";
internal const string XsltSettingsEnableScriptDiagId = "SYSLIB0062";

internal const string NamedPipeClientStreamIsConnectedMessage = "This constructor has been deprecated and argument bool isConnected does not have any effect. Use NamedPipeClientStream(PipeDirection direction, bool isAsync, SafePipeHandle safePipeHandle) instead.";
internal const string NamedPipeClientStreamIsConnectedDiagId = "SYSLIB0063";

// When adding a new diagnostic ID, add it to the table in docs\project\list-of-diagnostics.md as well.
// Keep new const identifiers above this comment.
}
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/System.IO.Pipes/ref/System.IO.Pipes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public void DisposeLocalCopyOfClientHandle() { }
}
public sealed partial class NamedPipeClientStream : System.IO.Pipes.PipeStream
{
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
[System.ObsoleteAttribute("This constructor has been deprecated and argument bool isConnected does not have any effect. Use NamedPipeClientStream(PipeDirection direction, bool isAsync, SafePipeHandle safePipeHandle) instead.", DiagnosticId = "SYSLIB0063", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public NamedPipeClientStream(System.IO.Pipes.PipeDirection direction, bool isAsync, bool isConnected, Microsoft.Win32.SafeHandles.SafePipeHandle safePipeHandle) : base (default(System.IO.Pipes.PipeDirection), default(int)) { }
public NamedPipeClientStream(System.IO.Pipes.PipeDirection direction, bool isAsync, Microsoft.Win32.SafeHandles.SafePipeHandle safePipeHandle) : base (default(System.IO.Pipes.PipeDirection), default(int)) { }
public NamedPipeClientStream(string pipeName) : base (default(System.IO.Pipes.PipeDirection), default(int)) { }
public NamedPipeClientStream(string serverName, string pipeName) : base (default(System.IO.Pipes.PipeDirection), default(int)) { }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
Expand Down
2 changes: 2 additions & 0 deletions src/libraries/System.IO.Pipes/src/System.IO.Pipes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<Compile Include="System\IO\Pipes\PipeTransmissionMode.cs" />
<Compile Include="$(CommonPath)DisableRuntimeMarshalling.cs"
Link="Common\DisableRuntimeMarshalling.cs" />
<Compile Include="$(CommonPath)System\Obsoletions.cs"
Link="Common\System\Obsoletions.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.ComponentModel;
using System.Diagnostics;
using System.Security;
using System.Security.Principal;
Expand Down Expand Up @@ -88,8 +89,14 @@ public NamedPipeClientStream(string serverName, string pipeName, PipeDirection d
_accessRights = AccessRightsFromDirection(direction);
}

// Create a NamedPipeClientStream from an existing server pipe handle.
[Obsolete(Obsoletions.NamedPipeClientStreamIsConnectedMessage, DiagnosticId = Obsoletions.NamedPipeClientStreamIsConnectedDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
[EditorBrowsable(EditorBrowsableState.Never)]
public NamedPipeClientStream(PipeDirection direction, bool isAsync, bool isConnected, SafePipeHandle safePipeHandle)
: this(direction, isAsync, safePipeHandle)
{
}

public NamedPipeClientStream(PipeDirection direction, bool isAsync, SafePipeHandle safePipeHandle)
: base(direction, 0)
{
ArgumentNullException.ThrowIfNull(safePipeHandle);
Expand All @@ -101,10 +108,7 @@ public NamedPipeClientStream(PipeDirection direction, bool isAsync, bool isConne
ValidateHandleIsPipe(safePipeHandle);

InitializeHandle(safePipeHandle, true, isAsync);
if (isConnected)
{
State = PipeState.Connected;
}
State = PipeState.Connected;
}

~NamedPipeClientStream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Security.Principal;
using System.Threading.Tasks;
using Microsoft.Win32.SafeHandles;
using Xunit;

Expand Down Expand Up @@ -99,7 +100,10 @@ public static void InvalidImpersonationLevel_Throws_ArgumentOutOfRangeException(
[InlineData(PipeDirection.Out)]
public static void NullHandle_Throws_ArgumentNullException(PipeDirection direction)
{
#pragma warning disable SYSLIB0063 // Testing the obsolete constructor
AssertExtensions.Throws<ArgumentNullException>("safePipeHandle", () => new NamedPipeClientStream(direction, false, true, null));
#pragma warning restore SYSLIB0063
AssertExtensions.Throws<ArgumentNullException>("safePipeHandle", () => new NamedPipeClientStream(direction, false, null));
}

[Theory]
Expand All @@ -109,7 +113,10 @@ public static void NullHandle_Throws_ArgumentNullException(PipeDirection directi
public static void InvalidHandle_Throws_ArgumentException(PipeDirection direction)
{
using SafePipeHandle pipeHandle = new SafePipeHandle(new IntPtr(-1), true);
#pragma warning disable SYSLIB0063 // Testing the obsolete constructor
AssertExtensions.Throws<ArgumentException>("safePipeHandle", () => new NamedPipeClientStream(direction, false, true, pipeHandle));
#pragma warning restore SYSLIB0063
AssertExtensions.Throws<ArgumentException>("safePipeHandle", () => new NamedPipeClientStream(direction, false, pipeHandle));
}

[Theory]
Expand All @@ -129,7 +136,10 @@ public static void BadHandleKind_Throws_IOException(PipeDirection direction)
IntPtr handle = safeHandle.DangerousGetHandle();

SafePipeHandle fakePipeHandle = new SafePipeHandle(handle, ownsHandle: false);
#pragma warning disable SYSLIB0063 // Testing the obsolete constructor
Assert.Throws<IOException>(() => new NamedPipeClientStream(direction, false, true, fakePipeHandle));
#pragma warning restore SYSLIB0063
Assert.Throws<IOException>(() => new NamedPipeClientStream(direction, false, fakePipeHandle));
}
finally
{
Expand All @@ -145,5 +155,46 @@ public static void NamedPipeClientStream_InvalidHandleInerhitability()
AssertExtensions.Throws<ArgumentOutOfRangeException>("inheritability", () => new NamedPipeClientStream("a", "b", PipeDirection.Out, 0, TokenImpersonationLevel.Delegation, HandleInheritability.None - 1));
AssertExtensions.Throws<ArgumentOutOfRangeException>("inheritability", () => new NamedPipeClientStream("a", "b", PipeDirection.Out, 0, TokenImpersonationLevel.Delegation, HandleInheritability.Inheritable + 1));
}

[Fact]
public static async Task ConnectOnPipeFromExistingHandle_Throws_InvalidOperationException()
{
string pipeName = PipeStreamConformanceTests.GetUniquePipeName();

using (var server1 = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 3, PipeTransmissionMode.Byte, PipeOptions.None))
using (var client1 = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None))
{
client1.Connect();
server1.WaitForConnection();

var clientFromHandle = new NamedPipeClientStream(PipeDirection.InOut, false, client1.SafePipeHandle);
Assert.Throws<InvalidOperationException>(clientFromHandle.Connect);
await Assert.ThrowsAsync<InvalidOperationException>(clientFromHandle.ConnectAsync);
}

#pragma warning disable SYSLIB0063
using (var server2 = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 3, PipeTransmissionMode.Byte, PipeOptions.None))
using (var client2 = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None))
{
client2.Connect();
server2.WaitForConnection();

var clientFromHandleTrue = new NamedPipeClientStream(PipeDirection.InOut, isAsync: false, isConnected: true, client2.SafePipeHandle);
Assert.Throws<InvalidOperationException>(clientFromHandleTrue.Connect);
await Assert.ThrowsAsync<InvalidOperationException>(clientFromHandleTrue.ConnectAsync);
}

using (var server3 = new NamedPipeServerStream(pipeName, PipeDirection.InOut, 3, PipeTransmissionMode.Byte, PipeOptions.None))
using (var client3 = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.None))
{
client3.Connect();
server3.WaitForConnection();

var clientFromHandleFalse = new NamedPipeClientStream(PipeDirection.InOut, isAsync: false, isConnected: false, client3.SafePipeHandle);
Assert.Throws<InvalidOperationException>(clientFromHandleFalse.Connect);
await Assert.ThrowsAsync<InvalidOperationException>(clientFromHandleFalse.ConnectAsync);
}
#pragma warning restore SYSLIB0063
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void InheritHandles_AvailableInChildProcess()

void ChildFunc(string handle)
{
using (var childClient = new NamedPipeClientStream(PipeDirection.Out, isAsync: false, isConnected: true, new SafePipeHandle((IntPtr)long.Parse(handle, CultureInfo.InvariantCulture), ownsHandle: true)))
using (var childClient = new NamedPipeClientStream(PipeDirection.Out, isAsync: false, new SafePipeHandle((IntPtr)long.Parse(handle, CultureInfo.InvariantCulture), ownsHandle: true)))
{
for (int i = 0; i < 5; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public async Task ClonedClient_ActsAsOriginalClient()

if (writeable is NamedPipeServerStream server)
{
using (NamedPipeClientStream client = new NamedPipeClientStream(PipeDirection.In, false, true, ((NamedPipeClientStream)readable).SafePipeHandle))
using (NamedPipeClientStream client = new NamedPipeClientStream(PipeDirection.In, false, ((NamedPipeClientStream)readable).SafePipeHandle))
{
if (OperatingSystem.IsWindows())
{
Expand All @@ -186,7 +186,7 @@ public async Task ClonedClient_ActsAsOriginalClient()
}
else
{
using (NamedPipeClientStream client = new NamedPipeClientStream(PipeDirection.Out, false, true, ((NamedPipeClientStream)writeable).SafePipeHandle))
using (NamedPipeClientStream client = new NamedPipeClientStream(PipeDirection.Out, false, ((NamedPipeClientStream)writeable).SafePipeHandle))
{
Task clientTask = client.WriteAsync(msg1, 0, msg1.Length);
int receivedLength = readable.Read(received1, 0, msg1.Length);
Expand Down
Loading