Skip to content

System.Net.Socket EndPoint-extensibility broken in corefx #15835

@stephentoub

Description

@stephentoub

The current corefx codebase appears to be closed off to any EndPoint customization. The Sockets codebase expects every EndPoint to be either a DnsEndPoint or an IPEndPoint, and anything that’s not built in to System.Net.Sockets will result in failures. This is a silly little quick example which obviously won’t do anything meaningful:

private class MyEndPoint : EndPoint { }

[Fact]
public void Socket_CustomEndPoint()
{
    Socket s = new Socket(SocketType.Raw, ProtocolType.Raw);
    s.Connect(new MyEndPoint());
}

but it fails on corefx due to a cast exception that highlights the problem:

System.InvalidCastException : Unable to cast object of type 'MyEndPoint' to type 'System.Net.IPEndPoint'.
        Stack Trace:
           c:\Users\stoub\Source\repos\corefx\src\Common\src\System\Net\Internals\IPEndPointExtensions.cs(14,0): at System.Net.Sockets.IPEndPointExtensions.Serialize(EndPoint endpoint)
           c:\Users\stoub\Source\repos\corefx\src\System.Net.Sockets\src\System\Net\Sockets\Socket.cs(4894,0): at System.Net.Sockets.Socket.CheckCacheRemote(EndPoint& remoteEP, Boolean isOverwrite)
           c:\Users\stoub\Source\repos\corefx\src\System.Net.Sockets\src\System\Net\Sockets\Socket.cs(848,0): at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)

In contrast, on desktop it also fails but where and with the exception I’d expect:

Unhandled Exception: System.NotImplementedException: This method is not implemented by this class.
   at System.Net.EndPoint.Serialize()
   at System.Net.Sockets.Socket.CallSerializeCheckDnsEndPoint(EndPoint remoteEP)
   at System.Net.Sockets.Socket.CheckCacheRemote(EndPoint& remoteEP, Boolean isOverwrite)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)

cc: @CIPop, @davidsh, @SidharthNabar

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions