Bug #25944 Illogical code in NativeDriver.cs, line 75 if using MySql versions 4.1.x
Submitted: 30 Jan 2007 13:32 Modified: 30 Jan 2007 14:15
Reporter: Carlos Mendonça Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:5.0.3 OS:Windows (Windows)
Assigned to: CPU Architecture:Any
Tags: Connection, NullReferenceException, open, query_cache_size, query_cache_type, serverprops

[30 Jan 2007 13:32] Carlos Mendonça
Description:
Greetings, I'm currently using MySql 4.1.9 and by running Connector/NET one will fall in an impossible condition that triggers a ReferenceNullException.

In file NativeDriver.cs, line 73, if the server version is 4.1.x, it will enter the condition and perform the next boolean operation in line 75. The problem is that the first time that this property (SupportsBatch) is called is at Driver.cs, line 159, right after the serverProps variable has been defined.

In other words, in order to get the server settings, i.e. fill serverProps variable, the method Configure (Driver.cs, line 174) executes the MySqlDataReader which will eventually fall into SupportsBatch property from NativeDriver.cs, and access serverProps which is not yet filled with the server variables.

How to repeat:
Run the following code against a MySql 4.1.x server (optionally, insert a breakpoint in line 75 of NativeDriver.cs):

MySqlConnection mySqlConnection;

try
{
  mySqlConnection = new MySqlConnection(YOUR_CONNECTION_STRING);
  mySqlConnection.Open();
}
catch (NullReferenceException)
{
  Console.WriteLine("There you go!");
}
finally
{
  if(mySqlConnection != null)
  {
    mySqlConnection.Close();
  }
}

Suggested fix:
Well, the thing is: you cannot look for "query_cache_type" and "query_cache_size" from serverProps variable while trying to actually retrieve it. What I did was comment lines 75 and 76 and so far the driver works great. Clearly that's not the solution at all, but there has to be some kind of condition that tells that in this first access that we're retrieving the server variables, they cannot be read in line 75.
[30 Jan 2007 14:15] Tonci Grgin
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments to the original bug instead.

Thank you for your interest in MySQL.

Explanation:
Hi Carlos. This is a duplicate of Bug#25726 (already fixed). If you feel the other way, please reopen the report and explain.