Bug #29476 NullException thrown when connecting to a 4.0.27 server
Submitted: 2 Jul 2007 5:49 Modified: 6 Sep 2007 10:38
Reporter: Ellery D'Souza Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:5.1.2.2 OS:Any
Assigned to: CPU Architecture:Any

[2 Jul 2007 5:49] Ellery D'Souza
Description:
Attempt to connect to a pre 4.1 server, and the following exception is thrown in MySqlField.CheckForExceptions (Field.cs):  

NullException - Object reference not set to an instance of an object

How to repeat:
Attempt to connect to a pre 4.1 server will throw the exception in MySqlField.CheckForExceptions.

Suggested fix:
Currently OriginalColumnName is set only by GetFieldMetaData41. Here is my modification for CheckForExceptions:
Index: Field.cs
===================================================================
--- Field.cs	(revision 774)
+++ Field.cs	(working copy)
@@ -234,8 +234,10 @@
 
         private void CheckForExceptions()
         {
-            string colName = OriginalColumnName.ToLower(CultureInfo.InvariantCulture);
-            if (colName.StartsWith("char("))
+            string colName = null;
+            if (OriginalColumnName != null)
+                colName = OriginalColumnName.ToLower(CultureInfo.InvariantCulture);
+            if (colName != null && colName.StartsWith("char("))
                 binaryOk = false;
             else if (connection.IsExecutingBuggyQuery)
                 binaryOk = false;
[16 Jul 2007 7:17] Tonci Grgin
Hi Ellery and thanks for your report. 

Verified as described by reporter:
 - MySQL server 4.0.30pro on WinXP Pro SP2 localhost
 - c/NET 5.1.2 SVN (latest sources) on NET fw 2.0
[10 Aug 2007 21:31] 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/32403
[10 Aug 2007 21:33] Reggie Burnett
Fixed in 5.1.3
[16 Aug 2007 14:52] 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/32645
[6 Sep 2007 10:38] MC Brown
A note has been added to the 5.1.3 changelog: 

Connecting to a MySQL server earlier than version 4.1 would raise a NullException.