Description:
Executing a prepared command that has a MySqlDbType.Date parameter fails with "MySqlException: Malformed communication packet." against MySQL Server 8.4.13, 9.7.4 and 26.10.0. The same code works against 8.0.46 and 26.7.0.
Since https://github.com/mysql/mysql-server/commit/3b856c5be30, these server releases validate the length of temporal parameters in COM_STMT_EXECUTE. A MYSQL_TYPE_DATE parameter must now have a length of 0 or 4. MySqlDateTime.WriteValue (binary protocol) always writes a 7-byte value for MySqlDbType.Date: year, month and day followed by three zero time bytes, or 11 bytes when there are microseconds. The server therefore rejects the packet.
How to repeat:
Run the following C# code:
using var connection = new MySqlConnection("...");
connection.Open();
using var command = new MySqlCommand("SELECT @value;", connection);
command.Parameters.Add("@value", MySqlDbType.Date).Value = new DateTime(2026, 8, 10);
command.Prepare();
command.ExecuteScalar(); // MySqlException: Malformed communication packet.
Suggested fix:
Only write four bytes: two for the year, one month, one day (or 0 bytes for 0000-00-00).