-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add constructor with string for SocketException #69266
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsBackground and motivationIn .NET Framework we used internal constructors to pass additional information (like EndPoint) to
This is no longer possible with .NET Core as the
or we omit additional useful information. API Proposalnamespace System.Net
{
public partial class SocketException : System.ComponentModel.Win32Exception
{
public SocketException() { }
public SocketException(int errorCode) { }
+ public SocketException(int errorCode, string? message) { }
} AlternativesInstead of API Usage
RisksThis is mostly for compatibility and primary use is runtime internals. PoC and additional discussion is in #68918 and #37150
|
Why is |
This is for cases when the source itself is nullable, like the EndPoint in sockets. With the current proposal I can do throw new SocketException(code, RightEndPoint?.ToString()); What I don't want is something like if (RightEndPoint != null)
{
throw new SocketException(code, RightEndPoint.ToString());
}
else
{
throw new SocketException(code);
} We could pass around empty string but that also feels weird. |
This is a long-existing problem and it is late for new APIs in 7.0, moving to 8.0. |
namespace System.Net.Sockets;
public partial class SocketException : Win32Exception
{
// Existing
// public SocketException();
// public SocketException(int errorCode);
public SocketException(int errorCode, string? message);
} |
Can I implement this, if you don't mind? @wfurt |
Background and motivation
In .NET Framework we used internal constructors to pass additional information (like EndPoint) to
SocketException
.For example when
Socket.Connect
fails we would see something likeThis is no longer possible with .NET Core as the
SocketException
lives inSystem.Net.Primitives
but the use of it comes fromSystem.Net.Sockets
andSystem.Net.NameResolution
. So we currently throw derived internal exception likeor we omit additional useful information.
API Proposal
namespace System.Net { public partial class SocketException : System.ComponentModel.Win32Exception { public SocketException() { } public SocketException(int errorCode) { } + public SocketException(int errorCode, string? message) { } }
Alternatives
Instead of
string
we could addEndPoint
as this is only additional information we use. Since we already use EndPoint.ToString(), the string seems more flexible as we may be able to pass in additional info in future.API Usage
Risks
This is mostly for compatibility and primary use is runtime internals.
PoC and additional discussion is in #68918 and #37150
The text was updated successfully, but these errors were encountered: