Bug #5621 MySqlParameterCollection.Add(null) exception message error.
Submitted: 17 Sep 2004 0:52 Modified: 28 Sep 2004 11:08
Reporter: Svetoslav Milenov
Status: Closed
Category:Connector/Net Severity:S3 (Non-critical)
Version: OS:
Assigned to: Reggie Burnett Target Version:

[17 Sep 2004 0:52] Svetoslav Milenov
Description:
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");

	_parms.Add(value);
	return value;
}

Cheers
[28 Sep 2004 11: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
    http://www.mysql.com/doc/en/Installing_source_tree.html