Bug #79855 Intermittent Object reference not set to an instance of an object on MySql.Data
Submitted: 5 Jan 2016 17:57 Modified: 19 Jun 2016 9:08
Reporter: Renato Xavier Email Updates:
Status: No Feedback Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version: OS:Microsoft Windows (64-bit)
Assigned to: Assigned Account CPU Architecture:Any
Tags: connector net, MySqlClient

[5 Jan 2016 17:57] Renato Xavier
I have a Windows Forms application, where the underlying database is MySql. Versions are as follows:

MySql Server v5.6

MySql Connector for .NET v6.5.4

Windows 7 64-bit

I get the error with the stack trace below, in an INTERMITTENT pattern. It happens each time in different parts of the application. Sometimes it takes a couple of days to happen, sometimes I get this 3 or 4 times a day.

On the specific occurrence where I collected this stack trace error, having the dialog box with the error still showing on the screen, I managed to open a second instance of my windows forms application, in parallel, only to notice that this second instance was working flawlessly. This is the pattern (or lack of it): whenever this issue shows up, just closing and restarting the application, or even opening another instance in parallel, is enough to restore database access. If I don't exit the application when this failure happens, all subsequent attempts the application makes to access MySql database fail, no matter what. The error dialog box option to "ignore this error and attempt to continue" allows me to conclude that it seems like MySql database backend and that particular instance of the windows forms application got "disconnected", even to subsequent attempts.

I understand that the stack trace information is a chain of events with the most recent at the top, so is it correct to assume that the failing point is at this event?

at MySql.Data.MySqlClient.NativeDriver.ExecutePacket(MySqlPacket packetToExecute)
I tried researching on this specific "MySql NativeDriver.ExecutePacket.. Object reference not set" everywhere, I could only get reports of people having this on seemingly unrelated issues with varying execution contexts, many of them even reporting as MySql bugs submitted to be fixed.

Anyway, I would appreciate any insight on the issue at hand, even suggestions on how to maybe properly debugging and even tuning MySql's configuration properties. I am open to any ideas.

See the end of this message for details on invoking 
    just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at MySql.Data.MySqlClient.NativeDriver.ExecutePacket(MySqlPacket packetToExecute)
   at MySql.Data.MySqlClient.NativeDriver.SendQuery(MySqlPacket queryPacket)
   at MySql.Data.MySqlClient.Driver.SendQuery(MySqlPacket p)
   at MySql.Data.MySqlClient.Statement.ExecuteNext()
   at MySql.Data.MySqlClient.PreparableStatement.ExecuteNext()
   at MySql.Data.MySqlClient.PreparableStatement.Execute()
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   at CodeFluent.Runtime.MySQL.CodeFluentMySQLPersistenceHook.SetForeignKeyChecks(MySqlConnection mySqlConnection)
   at CodeFluent.Runtime.MySQL.CodeFluentMySQLPersistenceHook.AfterOpenConnection(IDbConnection connection)
   at CodeFluent.Runtime.CodeFluentPersistence.OpenConnection()
   at CodeFluent.Runtime.CodeFluentPersistence.InternalExecuteReader(CommandBehavior behavior, Boolean firstTry)
   at CodeFluent.Runtime.CodeFluentPersistence.ExecuteReader(CommandBehavior behavior)
   at CodeFluent.Runtime.CodeFluentPersistence.ExecuteReader()
   at S5T.AssociadoSetorCob.LoadBypCodigo(Int32 pCodigo)
   at S5TWin.FormGeraArqBanco.cmbSetor_MontaPesquisaTextBox(String& desc)
   at S5TWin.ComboCF.txtCodigo_Leave(Object sender, EventArgs e)
   at System.Windows.Forms.Control.OnLeave(EventArgs e)
   at System.Windows.Forms.Control.NotifyLeave()
   at System.Windows.Forms.ContainerControl.UpdateFocusedControl()
************** Loaded Assemblies **************
    Assembly Version:
    Win32 Version: 4.0.30319.1022 (RTMGDR.030319-1000)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
    Assembly Version:
    Win32 Version: 4.0.30319.1001 built by: RTMGDR
    CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
Long list of loaded assemblies, cut short for brevity

How to repeat:
It is an intermittent pattern.
[6 Jan 2016 12:19] Chiranjeevi Battula
Hello Renato Xavier,

Thank you for the bug report.
I tried to reproduce the issue at my end using MySQL Connector/Net 6.9.8 but not seeing any issues in connections.
Please try with latest version of MySQL Connector/Net from below link.

[7 Feb 2016 1: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".
[18 May 2016 16:49] NOT_FOUND NOT_FOUND
I see similar issues with my WebApplication, which used Version 6.9.8 of MySql.Data and MySqlData.Entity

at MySql.Data.MySqlClient.NativeDriver.ExecutePacket(MySqlPacket packetToExecute)
at MySql.Data.MySqlClient.NativeDriver.SetDatabase(String dbName)
at MySql.Data.MySqlClient.MySqlConnection.ChangeDatabase(String databaseName)
at MySql.Data.MySqlClient.MySqlConnection.Open()
at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c_DisplayClass7.<GetResults>b_5()
at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at AsclepiusWeb.Core.Repository.UserFileRepository.findForUser(Int32 userId, ICollection`1 ignoreTypes, Boolean currentOnly, Boolean orderByRecent)
[19 May 2016 9:08] Chiranjeevi Battula

Thank you for your feedback.
Could you please provide repeatable test case (exact steps/sample project, connection string etc. - please make it as private if you prefer) to confirm this issue at our end?

[20 Jun 2016 1: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".