Skip to content
ecdsa.com
.NET SslStream / HttpClient.NET

Error message

Cannot determine the frame size or a corrupted frame was received.

Also printed as

  • System.Security.Authentication.AuthenticationException: Cannot determine the frame size or a corrupted frame was received.

Same text in .NET Core, .NET 5–10 and .NET Framework. HttpClient wraps it in "The SSL connection could not be established, see inner exception."

.NET SslStream / HttpClient — AuthenticationException when the peer's reply is not a TLS record

What it means

SslStream expected a TLS record header and got bytes that do not form one, so it cannot even tell how long the next frame is. The peer is not speaking TLS on that port — typically a plain-HTTP endpoint ("HTTP/1.1 400 …") reached with https://, or a protocol that starts in plain text.

Why it happens

How to fix it

  1. 1.

    Check what the port speaks

    If plain HTTP answers, use the HTTPS port or http://.

    bash
    curl -si http://api.example.com:8080/ | head -1    # answers over plain HTTP?
  2. 2.

    Use the HTTPS URL Kestrel listens on

    Check applicationUrl or ASPNETCORE_URLS and call the https:// address with its port.

    json
    {
      "profiles": {
        "https": {
          "commandName": "Project",
          "applicationUrl": "https://localhost:7001;http://localhost:5001"
        }
      }
    }
  3. 3.

    Mail: STARTTLS ports need STARTTLS

    With MailKit use SecureSocketOptions.StartTls on 587 and SslOnConnect only on 465.

    csharp
    // MailKit: STARTTLS on 587, implicit TLS (SslOnConnect) on 465
    await smtp.ConnectAsync("mail.example.com", 587, MailKit.Security.SecureSocketOptions.StartTls);

Related errors

Browse the full signature error database