In (desktop) .NET Framework, Socket.Select(....) throws a SocketException when one of the sockets that you specify is disposed:
System.Net.Sockets.SocketException (10038): An operation was attempted on something that is not a socket.
In .NET Core 2.1 and 3.1, this is also the exception that is thrown on Windows. On Linux, no exception is thrown.
Now in .NET 5.0 Preview 2, an ObjectDisposedException is thrown on both Windows and Linux:
System.ObjectDisposedException: Safe handle has been closed.
Object name: 'SafeHandle'.
at System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
at System.Net.Sockets.SocketPal.AddToPollArray(PollEvent* arr, Int32 arrLength, IList socketList, Int32& arrOffset, PollEvents events, Int32& refsAdded)
at System.Net.Sockets.SocketPal.SelectViaPoll(IList checkRead, Int32 checkReadInitialCount, IList checkWrite, Int32 checkWriteInitialCount, IList checkError, Int32 checkErrorInitialCount, PollEvent* events, Int32 eventsLength, Int32 microseconds)
at System.Net.Sockets.SocketPal.Select(IList checkRead, IList checkWrite, IList checkError, Int32 microseconds)
at System.Net.Sockets.Socket.Select(IList checkRead, IList checkWrite, IList checkError, Int32 microSeconds)
To reproduce, compile and run the following code fragment:
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
class SelectDisposed
{
private static void Main()
{
var endPoint = new IPEndPoint(IPAddress.Loopback, 8080);
var client = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
client.Dispose();
Socket.Select(new List<object> { client }, null, null, -1);
}
}
In (desktop) .NET Framework,
Socket.Select(....)throws a SocketException when one of the sockets that you specify is disposed:In .NET Core 2.1 and 3.1, this is also the exception that is thrown on Windows. On Linux, no exception is thrown.
Now in .NET 5.0 Preview 2, an ObjectDisposedException is thrown on both Windows and Linux:
To reproduce, compile and run the following code fragment: