diff --git a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj
index 3d4d3c791e27d2..ae0f96d5351e87 100644
--- a/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj
+++ b/src/libraries/System.Net.Sockets/src/System.Net.Sockets.csproj
@@ -80,6 +80,8 @@
Link="Common\System\Net\SocketAddress.cs" />
+
@@ -215,8 +217,6 @@
Link="Common\System\Net\SocketProtocolSupportPal.Unix" />
-
+ TaskToApm.Begin(AcceptSocketAsync(), callback, state);
- public Socket EndAcceptSocket(IAsyncResult asyncResult)
- {
- if (asyncResult == null)
- {
- throw new ArgumentNullException(nameof(asyncResult));
- }
-
- LazyAsyncResult? lazyResult = asyncResult as LazyAsyncResult;
- Socket? asyncSocket = lazyResult == null ? null : lazyResult.AsyncObject as Socket;
- if (asyncSocket == null)
- {
- throw new ArgumentException(SR.net_io_invalidasyncresult, nameof(asyncResult));
- }
-
- // This will throw ObjectDisposedException if Stop() has been called.
- return asyncSocket.EndAccept(asyncResult);
- }
+ public Socket EndAcceptSocket(IAsyncResult asyncResult) =>
+ TaskToApm.End(asyncResult);
public IAsyncResult BeginAcceptTcpClient(AsyncCallback? callback, object? state) =>
- BeginAcceptSocket(callback, state);
+ TaskToApm.Begin(AcceptTcpClientAsync(), callback, state);
public TcpClient EndAcceptTcpClient(IAsyncResult asyncResult) =>
- new TcpClient(EndAcceptSocket(asyncResult));
+ TaskToApm.End(asyncResult);
public Task AcceptSocketAsync()
{