Bug #67543 Object reference not set to an instance of an object in get_ServerThread()
Submitted: 9 Nov 2012 20:00 Modified: 15 May 2013 19:24
Reporter: Csaba Skultety Email Updates:
Status: Analyzing Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.5.4 OS:Microsoft Windows
Assigned to: Roberto Ezequiel Garcia Ballesteros CPU Architecture:Any

[9 Nov 2012 20:00] Csaba Skultety
Description:
I have an application which periodically polls the database for things to process. Occasionally, sometimes several times in a row or sometimes minutes apart, and sometimes hours or days apart it throws this error:

Object reference not set to an instance of an object.
   at MySql.Data.MySqlClient.MySqlConnection.get_ServerThread()
   at MySql.Data.MySqlClient.MySqlConnection.HandleTimeoutOrThreadAbort(Exception ex)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(MySqlConnection connection, MySqlTransaction transaction, String commandText, MySqlParameter[] commandParameters, Boolean ExternalConn)
   at MySql.Data.MySqlClient.MySqlHelper.ExecuteReader(String connectionString, String commandText, MySqlParameter[] commandParameters)

The call is made using MySqlHelper and passing in a connection string, not an actual connection. Also as I mentioned, it is pretty random and sometimes right after an error on the next iteration it fetches data from the database so it's not an issue with the server or connectivity to the server (at least it doesn't appear so).

How to repeat:
I cannot repeat it on demand, it appears in my logs randomly.
[11 Jan 2013 15:39] NOT_FOUND NOT_FOUND
As an additional note:

I have reason to suspect that the actual, correct exception is being masked by this null reference exception. So while the error is not necessarily "abnormal" from MySqlHelper, the fact that the null reference exception is masking the correct one is a defect.
[30 Oct 2014 10:39] Coleman Corrigan
I've hit the same issue on delete of a copied Connector from MySQL Workbench.
Similarly I think it masks a separate, underlying issue. Following a hard reset (power fault) MySQL Workbench would lock up windows when a connection was opened (consumed all memory and got into a system fatal malloc/paging spiral). 
I used Manage Server Connections window [Duplicate] to copy the connector, then when I used [Delete] to remove the original, I got said error.

In my case I'd two connectors to duplicate, both generated the MySQL Workbench Unexpected Error : Object reference not set to an instance of an object.

In both cases, following the error, [Test Connection] on the duplicated connectors then reported - Failed to Connect to MySQL at 127.0.0.1:3306 with user root
 Can't connect to MySQL server on '27.0.0.1' (10061)

Closing out the Manage Server Connections and opening the connectors via the main page worked fine , and on re-opening the Manage Server Connections window, connector hostnames were restored and [Test Connection] works as before.