SendFile throws NotSupportedException for connectionless sockets
The behavior of the SendFile method family for connectionless (for example, UDP) sockets is now consistent across all platforms. The affected methods now throw a NotSupportedException on all platforms.
Previous behavior
Previously, for a connectionless Socket (for example, UDP), the following behaviors were observed:
- SendFile threw a NotSupportedException on Windows, but not on Unix-like platforms.
- The ValueTask returned from SendFileAsync stored a SocketException on all platforms.
- Calling EndSendFile on an IAsyncResult returned from BeginSendFile threw a SocketException on all platforms.
New behavior
Starting in .NET 8, for a connectionless Socket (for example, UDP), the following behaviors are observed:
- SendFile throws a NotSupportedException on all platforms.
- The ValueTask returned from SendFileAsync stores a NotSupportedException on all platforms.
- Calling EndSendFile on an IAsyncResult returned from BeginSendFile throws a NotSupportedException on all platforms.
Version introduced
.NET 8 RC 1
Type of breaking change
This change is a behavioral change.
Reason for change
Given that SendFile
is typically used with large amounts of data, it doesn't make sense to use it with connectionless sockets. In addition, the previous behavior was inconsistent, throwing SocketException
on some platforms, while succeeding on others with an unpredictable outcome.
Recommended action
Do not use SendFile
methods for connectionless sockets.