Bug #105730 MySqlCommand.Clone doesn't clone attributes
Submitted: 27 Nov 2021 23:22 Modified: 13 Jan 22:57
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.27 OS:Any
Assigned to: CPU Architecture:Any

[27 Nov 2021 23:22] Bradley Grainger
Description:
MySqlCommand.Clone() returns a copy of the current command. However, the contents of the MySqlCommand.Attributes MySqlAttributeCollection are not copied to the cloned command.

How to repeat:
Run the following C# code:

using var cmd = new MySqlCommand();
cmd.Attributes.SetAttribute("attr", "value");
cmd.Parameters.AddWithValue("@param", "value");

var cmd2 = (MySqlCommand) cmd.Clone();

// prints 0; expected 1
Console.WriteLine(cmd2.Attributes.Count);

// prints 1 (as expected, because parameters are cloned)
Console.WriteLine(cmd2.Parameters.Count);

Suggested fix:
MySqlCommand.Clone should copy the contents of the Attributes collection.
[28 Nov 2021 9:58] MySQL Verification Team
Hello Bradley,

Thank you for the report and test case.
Verified as described.

regards,
Umesh
[13 Jan 22:57] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET 8.0.29 release, and here's the proposed changelog entry from the documentation team:

Although the MySqlCommand.Clone method returned a copy of the current
command, the contents of the MySqlCommand.Attributes collection
(MySqlAttributeCollection object) were not copied to the cloned command.

Thank you for the bug report.