diff --git a/src/Servers/Kestrel/Transport.Sockets/src/SocketConnectionListener.cs b/src/Servers/Kestrel/Transport.Sockets/src/SocketConnectionListener.cs
index ccdb774674..600d674d98 100644
--- a/src/Servers/Kestrel/Transport.Sockets/src/SocketConnectionListener.cs
+++ b/src/Servers/Kestrel/Transport.Sockets/src/SocketConnectionListener.cs
@@ -62,6 +62,13 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets
throw new InvalidOperationException(SocketsStrings.TransportAlreadyBound);
}
+ // Check if EndPoint is a FileHandleEndpoint before attempting to access EndPoint.AddressFamily
+ // since that will throw an NotImplementedException.
+ if (EndPoint is FileHandleEndPoint)
+ {
+ throw new NotSupportedException(SocketsStrings.FileHandleEndPointNotSupported);
+ }
+
Socket listenSocket;
// Unix domain sockets are unspecified
diff --git a/src/Servers/Kestrel/Transport.Sockets/src/SocketsStrings.resx b/src/Servers/Kestrel/Transport.Sockets/src/SocketsStrings.resx
index 52b26c66bc..58c6581609 100644
--- a/src/Servers/Kestrel/Transport.Sockets/src/SocketsStrings.resx
+++ b/src/Servers/Kestrel/Transport.Sockets/src/SocketsStrings.resx
@@ -117,6 +117,9 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ The Socket transport does not support FileHandleEndPoints. Consider using the libuv transport instead.
+
Only ListenType.IPEndPoint is supported by the Socket Transport. https://go.microsoft.com/fwlink/?linkid=874850
diff --git a/src/Servers/Kestrel/test/Sockets.BindTests/SocketTransportFactoryTests.cs b/src/Servers/Kestrel/test/Sockets.BindTests/SocketTransportFactoryTests.cs
new file mode 100644
index 0000000000..2ff92f497f
--- /dev/null
+++ b/src/Servers/Kestrel/test/Sockets.BindTests/SocketTransportFactoryTests.cs
@@ -0,0 +1,25 @@
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using System;
+using System.Threading.Tasks;
+using Microsoft.AspNetCore.Connections;
+using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets;
+using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
+using Moq;
+using Xunit;
+
+namespace Sockets.BindTests
+{
+ public class SocketTransportFactoryTests
+ {
+ [Fact]
+ public async Task ThrowsNotSupportedExceptionWhenBindingToFileHandleEndPoint()
+ {
+ var socketTransportFactory = new SocketTransportFactory(Options.Create(new SocketTransportOptions()), Mock.Of());
+ await Assert.ThrowsAsync(async () => await socketTransportFactory.BindAsync(new FileHandleEndPoint(0, FileHandleType.Auto)));
+ }
+ }
+}
+