runtime: SocketAddress with arbitrary AddressFamily throws PNSE on Unix

This succeeds on Windows:

new SocketAddress((AddressFamily)12345).ToString()

returning:

"12345:32:{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}"

but on Linux and macOS it throws:

Unhandled Exception of Type System.PlatformNotSupportedException
Message :
System.PlatformNotSupportedException : Operation is not supported on this platform.
Stack Trace :
   at System.Net.SocketAddressPal.ThrowOnFailure(Error err) in /_/src/Common/src/System/Net/SocketAddressPal.Unix.cs:line 51
   at System.Net.SocketAddressPal.SetAddressFamily(Byte[] buffer, AddressFamily family) in /_/src/Common/src/System/Net/SocketAddressPal.Unix.cs:line 76
   at System.Net.SocketAddress..ctor(AddressFamily family, Int32 size) in /_/src/Common/src/System/Net/SocketAddress.cs:line 96

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 26 (26 by maintainers)

Most upvoted comments

approved by Tactics. closed by dotnet/corefx#40235.

is 5.0-only fix ok?

No. If it doesn’t get into 3.0, it needs to be reverted from master. It’s a breaking change.

@danmosemsft, this is the kind of thing I was mentioning.