Getting unrecognized 0x800704C9 error with StreamSocket.UpgradeToSslAsync

0

I'm getting System.Exception with HResult=0x800704C9 when there is a pause between connecting and starting SSL handshake (so the remote server closes the connection).

await socket.UpgradeToSslAsync(SocketProtectionLevel.Tls12, socket.Information.RemoteHostName);

Windows.Networking.Sockets.SocketError.GetStatus(e.HResult) gives Unknown for 0x800704C9 code. Error Lookup tool, however, recognizes this code and indicates that 0x04C9/0x800704C9 codes correspond to "The remote computer refused the network connection." error.

However, CONNECTION REFUSED has its own code 0x274D ("No connection could be made because the target machine actively refused it."). It turns out that Windows has TWO error codes for the same and only one of them is recognized by SocketError class.

So what's the difference between 0x04C9 and 0x274D errors and is it a bug in SocketError.GetStatus so it understands only one of these codes?

My code relies heavily on SocketError.GetStatus != SocketErrorStatus.Unknown because this is no other way to determine if the occurred exception is general or network-related (all exceptions being thrown are of System.Exception class, not IOException or anything like).

I'm worrying what else network-related error can arise one day and not being recognized by SocketError.GetStatus..

c#
sockets
uwp
asked on Stack Overflow Dec 21, 2016 by Alex

1 Answer

0

HRESULT error: 0x8007274d

Winsock error: WSAECONNREFUSED (10061)

It means that No connection could be made because the target computer actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host—that is, one with no server application running

HRESULT error:0x800704c9

System Error Codes :ERROR_CONNECTION_REFUSED (1225)

It means that The remote computer refused the network connection.But it not one of Windows Sockets Error Codes.So Windows.Networking.Sockets.SocketError.GetStatus(e.HResult) gives Unknown for 0x800704C9 code.

answered on Stack Overflow Dec 23, 2016 by Nico Zhu - MSFT

User contributions licensed under CC BY-SA 3.0