I am connecting from my C# program (.NET 5.0) to a MySql database, however whenever I open the connection I get the following exception (the original has a longer traceback):
System.IO.IOException: Cannot determine the frame size or a corrupted frame was received.
at System.Net.Security.SslStream.ReceiveBlobAsync[TIOAdapter](TIOAdapter adapter)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
at System.Net.Security.SslStream.ProcessAuthentication(Boolean isAsync, Boolean isApm, CancellationToken cancellationToken)
at System.Net.Security.SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
at MySqlConnector.Core.ServerSession.InitSslAsync(ProtocolCapabilities serverCapabilities, ConnectionSettings cs, SslProtocols sslProtocols, IOBehavior ioBehavior, CancellationToken cancellationToken)
at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, Int32 startTickCount, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 470
After the exception is thrown, the program keeps working as usual and manages to connect to MySql.
I use MySqlConnector, using MySql.Data.MySqlClient gives the same problem. The code looks something like this:
using MySqlConnector;
...
string _myConnectionString = "Server=myserver;User=myUser;Database=myDatabase;Password=myPassword";
using MySqlConnection conn = new(_myConnectionString);
conn.Open(); // The exception is thrown here
...
I haven't found anything online, any idea on how to make the exception go away?
This may be cause by a failure to negotiate TLS 1.3. Try setting TLS Version
in your connection string:
Server=myserver; TLS Version=TLS 1.2; User=myUser; ...