Bug #83764 System.NullReferenceException: Object reference not set to an instance of an obj
Submitted: 10 Nov 2016 2:46 Modified: 11 May 2017 12:00
Reporter: nan su Email Updates:
Status: Can't repeat Impact on me:
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.6.23-log - MySQL Community Server OS:Microsoft Windows (WinServer2012R2 Standard)
Assigned to: CPU Architecture:Any
Tags: System.NullReferenceException

[10 Nov 2016 2:46] nan su
I'am using TransactionScope to do insert/update SQLcmd. throw errors below:

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.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   at MySql.Data.MySqlClient.MySqlTransaction.Rollback()
   at MySql.Data.MySqlClient.MySqlTransactionScope.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
   at MySql.Data.MySqlClient.MySqlPromotableTransaction.System.Transactions.IPromotableSinglePhaseNotification.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
   at System.Transactions.DurableEnlistmentAborting.EnterState(InternalEnlistment enlistment)
   at System.Transactions.TransactionStateAborted.EnterState(InternalTransaction tx)
   at System.Transactions.Transaction.Rollback()
   at System.Transactions.TransactionScope.InternalDispose()
   at System.Transactions.TransactionScope.Dispose()

How to repeat:
         using (var t = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                await db.SaveChangesAsync();
                    if (ask)
                        await cas.LockFundsAsync 
                        await cas.LockFundsAsync 
                catch (Exception ex)
                    throw new Accounting.CapitalAccountNoBalanceOpException(JsonConvert.SerializeObject(order), ex);

[10 Nov 2016 5:32] Chiranjeevi Battula
Hello nan,

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

[7 Dec 2016 14:27] Jörg Lippold
I'm experiencing this problem as well and so i have spent some time examining.

Doing the Rollback, the stream in NativeDriver is null when calling ExecutePacket(MySqlPacket). Unfortunately I cannot provide a simple sample project that reproduces the problem in detail. 

But I can provide the specific error message (at the end) and a corresponding test project (MySqlTestProject.rar, MySqlTestDb.rar) where I get the resulting UnhandledException :-(

Please try to deal with it contemporary. It actually affects our customers. Thank you.

*AppDomain::UnhandledException(): IsTerminating: True, Exception: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei MySql.Data.MySqlClient.NativeDriver.ExecutePacket(MySqlPacket packetToExecute)
   bei MySql.Data.MySqlClient.NativeDriver.SendQuery(MySqlPacket queryPacket)
   bei MySql.Data.MySqlClient.Driver.SendQuery(MySqlPacket p)
   bei MySql.Data.MySqlClient.Statement.ExecuteNext()
   bei MySql.Data.MySqlClient.PreparableStatement.ExecuteNext()
   bei MySql.Data.MySqlClient.PreparableStatement.Execute()
   bei MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
   bei MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   bei MySql.Data.MySqlClient.MySqlTransaction.Rollback()
   bei MySql.Data.MySqlClient.MySqlTransactionScope.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
   bei MySql.Data.MySqlClient.MySqlPromotableTransaction.System.Transactions.IPromotableSinglePhaseNotification.Rollback(SinglePhaseEnlistment singlePhaseEnlistment)
   bei System.Transactions.DurableEnlistmentAborting.EnterState(InternalEnlistment enlistment)
   bei System.Transactions.DurableEnlistmentActive.InternalAborted(InternalEnlistment enlistment)
   bei System.Transactions.TransactionStateAborted.EnterState(InternalTransaction tx)
   bei System.Transactions.TransactionStateActive.Rollback(InternalTransaction tx, Exception e)
   bei System.Transactions.EnlistableStates.Timeout(InternalTransaction tx)
   bei System.Transactions.Bucket.TimeoutTransactions()
   bei System.Transactions.BucketSet.TimeoutTransactions()
   bei System.Transactions.TransactionTable.ThreadTimer(Object state)
   bei System.Threading.TimerQueueTimer.CallCallbackInContext(Object state)
   bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.TimerQueueTimer.CallCallback()
   bei System.Threading.TimerQueueTimer.Fire()
   bei System.Threading.TimerQueue.FireNextTimers()
   bei System.Threading.TimerQueue.AppDomainTimerCallback()*
[7 Dec 2016 14:28] Jörg Lippold
Database for MySqlTestProject.rar

Attachment: MySqlTestDb.rar (application/octet-stream, text), 1.05 KiB.

[7 Dec 2016 14:28] Jörg Lippold
Raising an UnhandledException

Attachment: MySqlTestProject.rar (application/octet-stream, text), 462.09 KiB.

[22 Feb 2017 6:10] nan su
I'm sure MySql.Data.dll make this error. When Sqlcommand timeout,this Exception occurs.
Upgrade this  MySql.Data.dll can fix this problem.
[2 Mar 2017 7:37] Jörg Lippold
@nan su su 
What's the version number of (your) MySQL.Data.dll?
[5 Mar 2017 2:05] nan su
@Jörg Lippold

U can try this:
[28 Apr 2017 8:56] Chiranjeevi Battula
Hello nan,

Thank you for the bug feedback and testcast.
I could not repeat the issue at our end using with Visual Studio 2017, Connector/NET 6.9.9 and 7.0.6 IR3 version.

[28 Apr 2017 8:56] Chiranjeevi Battula

Attachment: 83764.JPG (image/jpeg, text), 205.02 KiB.

[6 May 2017 8:43] nan su

I mean  7.0.6 IR3 can FIX this error.

MySql.data(version raise TIMEOUT Exception for sure.
[11 May 2017 12:00] Chiranjeevi Battula
Hello nan,

Thank you for the feedback.
I could not repeat the issue at our end using with Visual Studio 2017, Connector/NET 6.9.9 and 7.0.6 IR3 version.
If you can provide more information, feel free to add it to this bug and change the status back to 'Open'.

Thank you for your interest in MySQL.