CLONE -Referenced version of Nhibernate.dll Throws Exception on Dispose of TransactionScope when in Distributed Transaction


ADO.NET Provider for SQL Server 2005
.NET Version 3.5SP1

In our application we have referenced version 1.0.0 of Linq.Nhibernate, which in it's turn references version of Nhibernate.dll

When a user creates a new entity in our application the entity has to be persisted to the database (using Nhibernate) and a message has to be persisted to a messagequeue. Both of these actions have to be performed in a single distributed transaction.

This is implemented by creating a TransactionScope which spans following code:

  • ISession.Flush (within it's own TransactionScope with ScopeOption.Required)

  • MessageQueue.Send (within it's own TransactionScope with ScopeOption.Required)

Both actions execute nicely and TransactionScope.Complete is called for both.
This is followed by a call to TransactionScope.Complete on the surrounding TransactionScope, no problem so far.

All the TransactionScopes are declared within a using block. When leaving the block of the surrounding TransactionScope (Dispose) following Exception is thrown:

Type: System.InvalidOperationException
Message: The operation is not valid for the current state of the enlistment.
at System.Transactions.TransactionState.Phase1VolatilePrepareDone(InternalTransaction tx)
at System.Transactions.Phase1VolatileEnlistment.CheckComplete()
at System.Transactions.Phase1VolatileEnlistment.FinishEnlistment()
at System.Transactions.VolatileEnlistmentPreparing.Prepared(InternalEnlistment enlistment)
at System.Transactions.PreparingEnlistment.Prepared()
at NHibernate.Impl.AbstractSessionImpl.System.Transactions.IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment)
at System.Transactions.VolatileEnlistmentPreparing.EnterState(InternalEnlistment enlistment)
at System.Transactions.VolatileEnlistmentActive.ChangeStatePreparing(InternalEnlistment enlistment)
at System.Transactions.TransactionStatePromotedPhase1.EnterState(InternalTransaction tx)
at System.Transactions.TransactionStatePromotedCommitting.ChangeStatePromotedPhase1(InternalTransaction tx)
at System.Transactions.Phase1VolatileDemultiplexer.InternalPrepare()
at System.Transactions.VolatileDemultiplexer.PoolablePrepare(Object state)
at System.Transactions.Phase1VolatileDemultiplexer.Prepare(IPromotedEnlistment en)
at System.Transactions.Oletx.OletxVolatileEnlistment.Prepare(OletxVolatileEnlistmentContainer container)
at System.Transactions.Oletx.OletxPhase1VolatileEnlistmentContainer.VoteRequest()
at System.Transactions.Oletx.OletxTransactionManager.ShimNotificationCallback(Object state, Boolean timeout)
at System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object state, Boolean timedOut)

We isolated the behavior into a testapplication without using any Nhibernate.Linq specific features, so that we could test the issue with a newer version of Nhibernate dll.
In this testproject the DTC transaction fails everytime we use a reference to Nhibernate
When we changed the reference to Nhibernate (as distributed on SourceFourge in package 2.0.1.GA) which we suppose is a newer version but with a lower version number, our code worked flawlessly.

We tried to compile Nhibernate.Linq with this version of Nhibernate.dll, but we got a bunch of compile errors.

Our application already heavily relies on the Nhibernate.Linq features so dropping this library is not an option. We understood that a later release of Nhibernate will contain Linq.Nhibernate, but momentarily we are blocked and cannot move our code into production, unless we don't use the distributed transaction, which is highly undesirable.

Is there any possibility to get a patch or could a Linq.Nhibernate version wich references Nhibernate be released?

Thanks in advance.
Diederik and Dries






Boris Karaberberov




Affects versions