Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
<!-- System.Net.Internals -->
<Compile Include="$(CommonPath)System\Net\Internals\IPAddressExtensions.cs"
Link="Common\System\Net\Internals\IPAddressExtensions.cs" />
<Compile Include="$(CommonPath)System\Net\Internals\SocketExceptionFactory.Windows.cs"
Link="Common\System\Net\Internals\SocketExceptionFactory.Windows.cs" />
<Compile Include="$(CommonPath)System\Net\SocketProtocolSupportPal.Windows.cs"
Link="Common\System\Net\SocketProtocolSupportPal.Windows" />
<Compile Include="$(CommonPath)System\Net\SocketAddressPal.Windows.cs"
Expand Down Expand Up @@ -81,10 +79,6 @@
Link="Common\System\Net\Internals\SocketAddressPal.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\SocketProtocolSupportPal.Unix.cs"
Link="Common\System\Net\SocketProtocolSupportPal.Unix" />
<Compile Include="$(CommonPath)System\Net\Internals\SocketExceptionFactory.cs"
Link="Common\System\Net\Internals\SocketExceptionFactory.cs" />
<Compile Include="$(CommonPath)System\Net\Internals\SocketExceptionFactory.Unix.cs"
Link="Common\System\Net\Internals\SocketExceptionFactory.Unix.cs" />
<Compile Include="$(CommonPath)Interop\Interop.CheckedAccess.cs"
Link="Common\System\Net\Internals\Interop.CheckedAccess.cs" />
<Compile Include="$(CommonPath)Interop\Unix\Interop.Errors.cs"
Expand Down
11 changes: 9 additions & 2 deletions src/libraries/System.Net.NameResolution/src/System/Net/Dns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ private static object GetHostEntryOrAddressesCore(string hostName, bool justAddr
if (errorCode != SocketError.Success)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(hostName, $"{hostName} DNS lookup failed with {errorCode}");
throw SocketExceptionFactory.CreateSocketException(errorCode, nativeErrorCode);
throw CreateException(errorCode, nativeErrorCode);
}

result = justAddresses ? (object)
Expand Down Expand Up @@ -440,7 +440,7 @@ private static object GetHostEntryOrAddressesCore(IPAddress address, bool justAd
if (errorCode != SocketError.Success)
{
if (NetEventSource.Log.IsEnabled()) NetEventSource.Error(address, $"{address} DNS lookup failed with {errorCode}");
throw SocketExceptionFactory.CreateSocketException(errorCode, nativeErrorCode);
throw CreateException(errorCode, nativeErrorCode);
}
Debug.Assert(name != null);
}
Expand Down Expand Up @@ -711,5 +711,12 @@ private static Task<TResult> RunAsync<TResult>(Func<object, long, TResult> func,

return task;
}

private static Exception CreateException(SocketError error, int nativeError)
{
SocketException e = new SocketException((int)error);
e.HResult = nativeError;
return e;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public async Task GetAddrInfoAsync_EmptyHost(bool justAddresses)

if (error == SocketError.HostNotFound && !OperatingSystem.IsWindows())
{
// On Unix, we are not guaranteed to be able to resove the local host. The ability to do so depends on the
// On Unix, we are not guaranteed to be able to resolve the local host. The ability to do so depends on the
// machine configurations, which varies by distro and is often inconsistent.
return;
}
Expand Down Expand Up @@ -393,7 +393,7 @@ public async Task GetAddrInfoAsync_HostName(bool justAddresses)

if (error == SocketError.HostNotFound && !OperatingSystem.IsWindows())
{
// On Unix, we are not guaranteed to be able to resove the local host. The ability to do so depends on the
// On Unix, we are not guaranteed to be able to resolve the local host. The ability to do so depends on the
// machine configurations, which varies by distro and is often inconsistent.
return;
}
Expand Down Expand Up @@ -463,7 +463,7 @@ public async Task GetAddrInfoAsync_UnknownHost(bool justAddresses)

const string hostName = "test.123";

SocketException socketException = await Assert.ThrowsAnyAsync<SocketException>(() => NameResolutionPal.GetAddrInfoAsync(hostName, justAddresses, AddressFamily.Unspecified, CancellationToken.None)).ConfigureAwait(false);
SocketException socketException = await Assert.ThrowsAsync<SocketException>(() => NameResolutionPal.GetAddrInfoAsync(hostName, justAddresses, AddressFamily.Unspecified, CancellationToken.None)).ConfigureAwait(false);
SocketError socketError = socketException.SocketErrorCode;

Assert.Equal(SocketError.HostNotFound, socketError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
Link="Common\System\Net\Sockets\ProtocolType.cs" />
<Compile Include="$(CommonPath)System\Net\Sockets\SocketType.cs" Condition="'$(TargetPlatformIdentifier)' == 'windows'"
Link="Common\System\Net\Sockets\SocketType.cs" />
<Compile Include="$(CommonPath)System\Net\Sockets\ProtocolFamily.cs"
Link="Common\System\Net\Sockets\ProtocolFamily.cs" />
<Compile Include="$(CommonPath)System\Net\IPEndPointStatics.cs"
Link="Common\System\Net\IPEndPointStatics.cs" />
<Compile Include="$(CommonPath)System\Net\IPAddressParserStatics.cs"
Expand Down Expand Up @@ -69,8 +71,6 @@
Link="Common\Interop\Windows\WinSock\Interop.WSASocketW.cs" />
<Compile Include="$(CommonPath)Interop\Windows\WinSock\Interop.SocketConstructorFlags.cs"
Link="Common\Interop\Windows\WinSock\Interop.SocketConstructorFlags.cs" />
<Compile Include="$(CommonPath)System\Net\Sockets\ProtocolFamily.cs"
Link="Common\System\Net\Sockets\ProtocolFamily.cs" />
<Compile Include="$(CommonPath)Interop\Windows\WinSock\Interop.GetAddrInfoExW.cs"
Link="Common\Interop\Windows\WinSock\Interop.GetAddrInfoExW.cs" />
</ItemGroup>
Expand All @@ -81,10 +81,6 @@
Link="Common\System\Net\Internals\Interop.CheckedAccess.cs" />
<Compile Include="$(CommonPath)System\Net\InteropIPAddressExtensions.Unix.cs"
Link="Common\System\Net\InteropIPAddressExtensions.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\Internals\SocketExceptionFactory.cs"
Link="ProductionCode\Common\System\Net\Internals\SocketExceptionFactory.cs" />
<Compile Include="$(CommonPath)System\Net\Internals\SocketExceptionFactory.Unix.cs"
Link="ProductionCode\Common\System\Net\Internals\SocketExceptionFactory.Unix.cs" />
<Compile Include="..\..\src\System\Net\NameResolutionPal.Unix.cs"
Link="ProductionCode\System\Net\NameResolutionPal.Unix.cs" />
<Compile Include="$(CommonPath)System\Net\SocketProtocolSupportPal.Unix.cs"
Expand Down