title: C# tls1.3 Exception: Cannot determine the frame size or a corrupted frame was received
body: <p>I want to test tls1.3, so i created a console app in VS 2019(Version 16.7.7) and the target framework is .NET Core 3.1.
  <a href="https://i.stack.imgur.com/aOrZM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aOrZM.png" alt="enter image description here" /></a></p>
  <p>My Program.cs</p>
  <pre><code>using System;
  using System.Net.Security;
  using System.Net.Sockets;
  using System.Security.Authentication;
  using System.Security.Cryptography;
  using System.Security.Cryptography.X509Certificates;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace TestSsl {
      class Program {
          static void Main(string[] args) {
              SslProtocols protocol = SslProtocols.Tls13;
              Console.WriteLine($&quot;testing SslProtocols.{protocol}&quot;);
              int port = 1999;
              RemoteCertificateValidationCallback certificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =&gt; {
                  return (true);
              };
              X509Certificate2 serverCert = new X509Certificate2(&quot;server.pfx&quot;, &quot;testpass123&quot;);
              X509Certificate2 clientCert = new X509Certificate2(&quot;client.pfx&quot;, &quot;testpass123&quot;);
              TcpListener server = TcpListener.Create(port);
              server.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
              server.Server.NoDelay = true;
              server.Server.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
              server.Start();
              Task taskServer = Task.Run(() =&gt; {
                  TcpClient romoteClient = server.AcceptTcpClient();
                  Task.Run(() =&gt; {
                      using(romoteClient) {
                          using(SslStream sslStreamRomoteClient = new SslStream(romoteClient.GetStream(), false, certificateValidationCallback)) {
                              try {
                                  sslStreamRomoteClient.AuthenticateAsServer(serverCert, true, protocol, true);
                                  byte[] buf = new byte[1000];
                                  int len = sslStreamRomoteClient.Read(buf, 0, buf.Length);
                                  string receive = Encoding.UTF8.GetString(buf, 0, len);
                                  Console.WriteLine($&quot;server receive:{receive}&quot;);
                                  sslStreamRomoteClient.Write(Encoding.UTF8.GetBytes(&quot;Ok&quot;));
                                  Console.WriteLine($&quot;server send:Ok&quot;);
                              } catch(Exception ex) {
                                  Console.WriteLine(ex);
                              }
                          }
                      }
                  }).Wait();
              });
              Task taskClient = Task.Run(() =&gt; {
                  try {
                      using(TcpClient client = new TcpClient()) {
                          client.Connect(&quot;127.0.0.1&quot;, port);
                          using(SslStream sslStreamClient = new SslStream(client.GetStream(), false, certificateValidationCallback)) {
                              sslStreamClient.AuthenticateAsClient(&quot;127.0.0.1&quot;, new X509CertificateCollection() { clientCert }, protocol, true);
                              string send = &quot;hi, i am testing tls&quot;;
                              sslStreamClient.Write(Encoding.UTF8.GetBytes(send));
                              Console.WriteLine($&quot;client send:{send}&quot;);
                              byte[] buf = new byte[1000];
                              int len = sslStreamClient.Read(buf);
                              string receive = Encoding.UTF8.GetString(buf, 0, len);
                              Console.WriteLine($&quot;client receive:{receive}&quot;);
                          }
                      }
                  } catch(Exception ex) {
                      Console.WriteLine(ex);
                  }
              });
              Task.WaitAll(taskClient, taskServer);
          }
      }
  }
  </code></pre>
  <p>And then according to <a href="https://stackoverflow.com/questions/56072561/how-to-enable-tls-1-3-in-windows-10/59210166#59210166">how to enable TLS 1.3 in windows 10</a> i enabled TLS 1.3 in regedit.
  <a href="https://i.stack.imgur.com/nw8EF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nw8EF.png" alt="TLS1.3 client" /></a></p>
  <p><a href="https://i.stack.imgur.com/yqVMU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yqVMU.png" alt="TLS1.3 server" /></a></p>
  <p>My PC information:</p>
  <p><a href="https://i.stack.imgur.com/vRfGX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vRfGX.png" alt="enter image description here" /></a></p>
  <p>Then i debug my project and met a exception</p>
  <p><a href="https://i.stack.imgur.com/JIN5Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JIN5Q.png" alt="enter image description here" /></a></p>
  <p>The debug console:</p>
  <p><a href="https://i.stack.imgur.com/gfl1v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gfl1v.png" alt="enter image description here" /></a></p>
  <p>Are there any requirements for these pfx certificate?</p>
  <p>How can solve this exception? Please help. Thanks.</p>