本文へスキップ
ecdsa.com
.NET HttpClient.NET

エラーメッセージ

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

別の表記

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

この文言は .NET Core 3.x から .NET 10 まで変わりません。フレームワーク(Refit、gRPC、Azure SDK)がさらにもう一度ラップすることがあるため、内部例外が 2〜3 階層下にある場合もあります。

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

このエラーの意味

接続中に発生したあらゆる TLS の失敗を包む、HttpClient の汎用的なラッパーです。メッセージ自体には診断情報がなく、実際の理由は InnerException(証明書の問題を示す AuthenticationException、またはトランスポートからの IOException)にあります。e.Message だけをログに記録すると理由が隠れてしまうため、例外チェーン全体を記録してください。

発生する理由

修正方法

  1. 1.

    例外チェーン全体をログに記録する

    本当の原因を確認するには、InnerException をたどってください(または Message だけでなく例外オブジェクト全体をログに記録してください)。

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

    内部のメッセージを原因に対応付ける

    内部のメッセージごとに対処法が異なります。下の関連項目で 1 つずつ取り上げています。

    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)

関連するエラー

署名エラーデータベースをすべて見る