Skip to content
ecdsa.com
.NET HttpClient.NET

Error message

The SSL connection could not be established, see inner exception.

Also printed as

  • System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.

The text is stable across .NET Core 3.x to .NET 10. Frameworks (Refit, gRPC, Azure SDKs) may wrap it once more, so the inner exception can be two or three levels down.

.NET HttpClient — HttpRequestException wrapping the AuthenticationException or IOException of the TLS handshake

What it means

HttpClient's generic wrapper for any TLS failure while connecting. The message itself carries no diagnosis: the actual reason is in InnerException (an AuthenticationException naming the certificate problem, or an IOException from the transport). Logging only e.Message hides it; log the whole exception chain.

Why it happens

How to fix it

  1. 1.

    Log the full exception chain

    Walk InnerException (or log the exception object, not just Message) to see the real cause.

    csharp
    catch (HttpRequestException e)
    {
        for (Exception? ex = e; ex != null; ex = ex.InnerException)
            logger.LogError("{Type}: {Message}", ex.GetType().FullName, ex.Message);
    }
  2. 2.

    Map the inner message to its cause

    Each inner message points to a different fix; the related entries below cover them one by one.

    text
    Inner exception                                                       -> look at
    "...errors in the certificate chain: UntrustedRoot / PartialChain"    -> trust store, server chain
    "...errors in the certificate chain: NotTimeValid"                    -> dates, clock
    "...validation procedure: RemoteCertificateNameMismatch"              -> host name vs SAN
    "Cannot determine the frame size or a corrupted frame was received."  -> port is not TLS
    "Received an unexpected EOF or 0 bytes from the transport stream."    -> server/proxy closed
    "SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL."            -> protocol/cipher (Linux)

Related errors

Browse the full signature error database