| Bug #93370 | MySqlParameterCollection.Add precondition check isn't consistent | ||
|---|---|---|---|
| Submitted: | 27 Nov 2018 17:20 | Modified: | 25 Oct 2022 17:09 |
| Reporter: | Bradley Grainger (OCA) | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connector / NET | Severity: | S3 (Non-critical) |
| Version: | 8.0.13 | OS: | Windows (10) |
| Assigned to: | CPU Architecture: | Other (x64) | |
[28 Nov 2018 6:12]
MySQL Verification Team
Hello Bradley, Thank you for the report and test case. Observed with VS 2017 (C#.Net) and Connector/NET 8.0.13 version. regards, Umesh
[23 Sep 2022 18:10]
Omar Chavez
Posted by developer: Verified using Connector/Net version 8.0.30
[21 Oct 2022 18:12]
Omar Chavez
Posted by developer: This patch changes how the verification of an existing parameter is made in the MySqlParameterCollection.Add method
[25 Oct 2022 17:09]
Christine Cole
Posted by developer: Fixed as of the upcoming MySQL Connector/NET 8.0.32 release, and here's the proposed changelog entry from the documentation team: Improved validation now ensures that the MySqlParameterCollection.Add() method behaves consistently when it checks whether a named parameter has been added already. Thank you for the bug report.

Description: MySqlParameterCollection.Add checks if a named parameter has already been added, but it throws inconsistently based on the order in which parameters are added. For example, assume that `cmd` is a MySqlCommand object. cmd.Parameters.AddWithValue("foo", 1); cmd.Parameters.AddWithValue("foo", 2); ^ throws MySqlException: Parameter 'foo' has already been defined. cmd.Parameters.AddWithValue("foo", 1); cmd.Parameters.AddWithValue("@foo", 2); ^ throws MySqlException: Parameter '@foo' has already been defined. cmd.Parameters.AddWithValue("@foo", 1); cmd.Parameters.AddWithValue("@foo", 2); ^ throws MySqlException: Parameter '@foo' has already been defined. cmd.Parameters.AddWithValue("@foo", 1); cmd.Parameters.AddWithValue("foo", 2); ^ doesn't throw The last example should be consistent with the first three and throw a MySqlException that "Parameter 'foo' has already been defined." How to repeat: Run the following C# code: using (var connection = new MySqlConnection("...")) { connection.Open(); using (var cmd = connection.CreateCommand()) { cmd.Parameters.AddWithValue("@foo", 1); cmd.Parameters.AddWithValue("foo", 2); // expect exception to be thrown but it isn't } }