Bug #15274 Use MySqlDbType.UInt32, throwed exception 'Only byte arrays can be serialize'
Submitted: 27 Nov 2005 15:28 Modified: 1 Jun 2006 21:49
Reporter: Wei Chen Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:1.0.7 OS:Windows (Windows)
Assigned to: CPU Architecture:Any

[27 Nov 2005 15:28] Wei Chen
Description:
when i use 

     sqlCommand.Parameters.Add("?userID", MySqlDbType.UInt32).Value = NextID;

     .....
     connection.open();
     sqlCommand.ExecuteNonQuery();

it will throw exception 'Only byte arrays can be serialize'

How to repeat:
sqlCommand.Parameters.Add("?userID", MySqlDbType.UInt32).Value = NextID;

use MySqlDbType.Uint32
[27 Nov 2005 17:46] Vasily Kishkin
Could you please say me what version of mysqld you use ?
[28 Nov 2005 15:29] Wei Chen
I use MySQL version is 5.0.16 and .net connecter is 1.0.7
[2 Dec 2005 10:01] Vasily Kishkin
Sorry...I was not able to reproduce the bug on my test case. Could you please say me declaration of NextID ?
[23 Dec 2005 21:15] Greg Adams
If it is any help, I have had similar problem, posted info to forum as I have begun by assuming I'm doing something wrong, as the message is coming from MySqlBinary, though I am trying to use MySqlUInt32.  Here is text I posted:

Environment: 
Using Connector 1.0.7 with mysql Ver 12.18 Distrib 4.0.12, for sun-solaris2.8 (sparc) 
OS = Windows 2000 Professional 
Framework = 1.1 

The "only byte arrays and strings can be serialized by MySqlBinary" has been being thrown every time I try to use a particular MySqlCommand via the UpdateCommand property of MySqlDataAdapter. I recompiled the current MySql.Data build with debug set and discovered that, to my surprise, the failure was coming from a field (ProjectId) that I thought was defined as: 
- an integer to MySql 
(create table Projects (ProjectId integer unique auto_increment primary key, 

- an xsd:int in the schema used to generate the dataset (xsd /d /n:xxxx yyy.xsd) 
<xsd:element name="ProjectId" msdata:ReadOnly="True" 
msdata:AutoIncrement="True" type="xsd:int"/> 

- a UInt32 to Connector 1.0.7 
MySqlParameter projidParm = new MySqlParameter("?ProjectId", 
MySqlDbType.UInt32,4,"ProjectId") ; 
projidParm.SourceVersion = DataRowVersion.Original ; 
projUpdate.Parameters.Add(projidParm) ; 
daProjects.UpdateCommand = projUpdate ; 

Tracing the serialization method in MySqlBinary I found that the System.Int32 field was going to MySqlBinary instead of MySqlInt32. My question is: What determines which type is to be used. I know the problem has to be in the Parm processing, because when I changed the ?ProjectId in the command text to a hardcoded value, the update was performed properly. However I cannot see any place in which the parm is inadvertently defined as a value that I would expect to trigger MySqlBinary. 

What determines which type is to be called for Serialization? How would you recommend I proceed to find the point at which the wrong path is taken?

-- end of original post --
If you need, after Christmas I can send you the commands used to create the MySql tables and source that is giving me the issue consistently.
[27 Dec 2005 13:58] Greg Adams
The issue appears to be due to the lack of a case statement for MySqlDbType.UInt32 in the static method GetMySqlValue of MySqlValue.  The method is defigned with signature 
   internal static MySqlValue GetMySqlValue( MySqlDbType type, bool unsigned, bool binary )

On entry, type = MySqlDbType.UInt32, bool=false, binary=true.  Logic drops to default case as there is no UInt32 case, and there decides to go to MySqlBinary because binary is true.  This causes exception because MySqlBinary does not expect to receive anything but strings and byte arrays.  I can circumvent issue by changing my references to MySqlDbType.UIntxx to Intxx, but would prefer to be able to use unsigned values when a value will never be negative.
[3 Jan 2006 0: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".
[30 May 2006 8:01] Tonci Grgin
Hi.
Verified as described by user:

        static void Main(string[] args)
        {
			MySqlConnection mycon = new             MySqlConnection("SERVER=munja;DATABASE=test;PORT=3307;userid=root;password=;pooling=false");
			mycon.Open();
			MySqlCommand comm = new MySqlCommand("SELECT * FROM test WHERE (idfield > ?id)", mycon);
			comm.Parameters.Add("?id", MySqlDbType.UInt16).Value = 32;
			MySqlDataReader dr = comm.ExecuteReader();
			dr.Read();
			UInt16 res = dr.GetUInt16(0);
            Console.WriteLine("Result=" + res.ToString());
        
        }
It is not only UInt32 that fails but also UInt16.
[1 Jun 2006 21:49] Reggie Burnett
This bug was related to and fixed by the patch for bug #18570.  The fix will be in 1.0.8
[1 Jun 2006 21:51] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/7186