Bug #93527 MySqlClient.Field.SetFieldEncoding doesn't check whether the key exists
Submitted: 8 Dec 2018 9:02 Modified: 10 Jan 2019 7:41
Reporter: wy duan Email Updates:
Status: No Feedback Impact on me:
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.13 OS:Microsoft Windows
Assigned to: CPU Architecture:Any
Tags: CharacterSetIndex, charsets, SetFieldEncoding

[8 Dec 2018 9:02] wy duan
In the MySqlClient.Field.SetFieldEncoding method,it doesn't check whether the key exists.

Now,the code is:if (charSets[CharacterSetIndex] == null) return;
I think it should be:if (!charSets.ContainsKey(CharacterSetIndex) || charSets[CharacterSetIndex] == null) return;

How to repeat:
1:Create a MySQL database named testdb as utf8
2:execute sql:
CREATE TABLE `test`  (
  `id` int(11) NOT NULL,
  `title` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL,
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
insert into test values(1,'测试中文');
3:Start a mycat server that connect to testdb 
4:Create a windows application using VS2017
5:install MySQL.Data 8.0.13 package through Nuget
6:execute the sql 'select title from test where id=1;' using MySQLCommand through mycat
7:you will recieve an exception "The given key was not present in the dictionary";

Suggested fix:
if (!charSets.ContainsKey(CharacterSetIndex) || charSets[CharacterSetIndex] == null) return;
[9 Dec 2018 15:37] MySQL Verification Team
Thank you for the bug report. Please provide your connection string. Thanks.
[10 Dec 2018 1:03] wy duan
server=;Port=8866;User Id=test;password=123456789;Database=mjnvdb;Allow User Variables=True;
[10 Dec 2018 7:41] MySQL Verification Team
Thank you for the feedback. This was already reported, please check:


[11 Jan 2019 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".