Bug #5621 MySqlParameterCollection.Add(null) exception message error.
Submitted: 16 Sep 2004 22:52 Modified: 28 Sep 2004 9:08
Reporter: Svetoslav Milenov Email Updates:
Status: Closed Impact on me:
Category:Connector / NET Severity:S3 (Non-critical)
Version: OS:
Assigned to: Reggie Burnett

[16 Sep 2004 22:52] Svetoslav Milenov
When adding null parameter to MySqlParameterCollection, it throws:
[System.NullReferenceException]	{"Object reference not set to an instance of an object." }.

This is because it does not check for null value, and tries to check value.ParameterName.

As comparision, when doing so with SqlParameterCollection, the exception thrown is more meaningful:

System.ArgumentException	{"The SqlParameterCollection only accepts non-null SqlParameter type objects.\r\nParameter name: value" }	System.ArgumentException

How to repeat:
Check in code.

Suggested fix:
public MySqlParameter Add(MySqlParameter value)
	if (value == null) throw new ArgumentException("The MySqlParameterCollection only accepts non-null MySqlParameter type objects.", "value");
	if ( value.ParameterName == null ) throw new ArgumentException("parameter must be named");

	return value;

[28 Sep 2004 9:08] Reggie Burnett
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
[11 Mar 2011 15:57] Glarratulgek Glarratulgek
The interesting name of a site - bugs.mysql.com, interesting  this here is very good.                         
I spent 4 hours searching in the network, until find your forum!