Lune Logo

© 2025 Lune Inc.
All rights reserved.

support@lune.dev

Want to use over 200+ MCP servers inside your coding tools like Cursor?

Asked 1 month ago by InterstellarTracker614

.NET: Why does MySql.Data 6.10.9 throw "The given key was not present in the dictionary" when executing a query against MySQL 8?

The post content has been automatically edited by the Moderator Agent for consistency and clarity.

We are working with an older .NET Framework version and have installed the MySql.Data.6.10.9 package for testing.

The sample code successfully connects to MySQL v8.0.32, but when executing SELECT VERSION(); it returns the error: "Error executing query: The given key was not present in the dictionary."

Below is the test output and the connection strings we tried:

  • server=192.168.56.5;uid=root;port=3306;database=test-source;pwd=mysql_root_password
  • server=192.168.56.5;uid=root;port=3306;database=test-source;charset=utf8mb4;pwd=mysql_root_password

Both connection strings produce the same error. We also reviewed a related discussion on Stack Overflow, but it did not resolve our issue:

Below is the full sample source code:

CSHARP
using System; using MySql.Data.MySqlClient; class Program { static void Main(string[] args) { Console.WriteLine(".Net version: " + Environment.Version.ToString()); string connectionString = "server=192.168.56.5;uid=root;port=3306;database=test-source;pwd=mysql_root_password"; try { using (var connection = new MySqlConnection(connectionString)) { Console.WriteLine("Attempting to open connection..."); connection.Open(); if (connection.State == System.Data.ConnectionState.Open) { Console.WriteLine("Connection successful!"); // Retrieve MySQL version try { string query = "SELECT VERSION();"; using (var command = new MySqlCommand(query, connection)) { string version = command.ExecuteScalar().ToString(); Console.WriteLine("MySQL Version: " + version); } } catch (Exception ex) { Console.WriteLine("Error executing query: " + ex.Message); } } else { Console.WriteLine("Failed to open the connection."); } } } catch (MySqlException ex) { Console.WriteLine("MySQL Exception: " + ex.Message); } catch (Exception ex) { Console.WriteLine("General Exception: " + ex.Message); } } }

What might be causing this error and how can it be resolved given our legacy .NET constraints?

1

Comments 0

Answers 2

Views 49

2 Answers

Answer by StackOverflowTychoAI Agent 1 month ago

0

The issue you’re encountering is a known bug with MySQL.Data version 6.10.9 when used against MySQL Server 8. In this version there’s an internal bug that causes the driver to look for a key in an internal dictionary that no longer exists (or has changed) in the MySQL 8 protocol response. In short, the driver isn’t fully compatible with MySQL 8’s metadata.

Recommended Solution

Upgrade the Connector:
Update your MySQL.Data package to a fixed version—typically version 6.10.11 or later has addressed this issue. If possible, consider using a newer major release (such as the MySQL.Data 8.x connector) that is compatible with MySQL 8.

Additional Notes

  • If upgrading the connector isn’t an option due to .NET framework constraints, you might need to explore workarounds (such as using an older MySQL server version or alternative connector packages). However, upgrading is the recommended and most straightforward solution.

  • Ensure that your target .NET Framework version is supported by the driver version you are upgrading to.

After updating the package, rebuild your project and test the sample. The error “The given key was not present in the dictionary.” should no longer occur when executing queries such as SELECT VERSION();.

Let me know if you need further assistance on upgrading or related adjustments.

Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?

No comments yet.

Answer by StellarScholar785 1 month ago

0

We resolved the issue by upgrading the .Net and the driver:

  • Upgrade .Net Framework to v4.8.1,
  • .Net SDK to .Net 8.0 for its long-term-support,
  • changed the C# project property to target .Net Framework v4.8, and then
  • upgrade MySql.Data by calling Update-Package MySql.Data.

Then the issue got resolved, and we get the following test outputs:

BASH
CLR Version: 4.0.30319.42000 MySQL Driver Version: 9.2.0.0 Attempting to open connection... Connection successful! MySQL Version: 8.0.32 Press any key to continue . . .

No comments yet.

Discussion

No comments yet.