I am calling dispose on the UnitOfWork (see the HandleEndMessage() method 
below).

I think the problem is actually in ActiveRecord's AbstractScope.PerformDisposal 
method.  It's calling Close rather than Dispose.  I think its patch time for AR!

________________________________
From: nhusers@googlegroups.com [mailto:nhus...@googlegroups.com] On Behalf Of 
Ayende Rahien
Sent: Friday, February 13, 2009 5:35 PM
To: nhusers@googlegroups.com
Subject: [nhusers] Re: System.Transactions with NH/AR/Rhino/NServiceBus

You need to call Dispose, not Close.
On Sat, Feb 14, 2009 at 2:07 AM, Tyler Burd 
<tb...@cudc.org<mailto:tb...@cudc.org>> wrote:

Hi all.  This one might be for Ayende...



I'm trying to use NHibernate with System.Transactions (since Ayende informed me 
he put a good deal of work into it).  My stack is NServiceBus trunk, NHibernate 
trunk, Rhino.Commons trunk, and ActiveRecord trunk.



I'm trying to create a UnitOfWorkMessageModule for NServiceBus, and my code 
looks like this:



public class UnitOfWorkMessageModule : IMessageModule

{

            public void HandleBeginMessage()

            {

                        UnitOfWork.Start();

            }



            public void HandleEndMessage()

            {

                        if (UnitOfWork.Current != null)

                        {

                                    UnitOfWork.Current.Flush();

                                    UnitOfWork.Current.Dispose();

                        }

            }

}



Before HandleBeginMessage, NServiceBus opens a new 
System.Transactions.TransactionScope, and after HandleEndMessage it closes the 
transaction.  However, when I go to dispose of the UnitOfWork I get this 
exception:



Failure in HandleEndMessage of message module: 
IDL.Core.Facilities.NServiceBus.MessageModules.UnitOfWorkMessageModule

 System.InvalidOperationException: Disconnect cannot be called while a 
transaction is in progress.

   at NHibernate.AdoNet.ConnectionManager.Disconnect() in 
d:\oss\nhibernate-trunk\src\NHibernate\AdoNet\ConnectionManager.cs:line 158

   at NHibernate.AdoNet.ConnectionManager.Close() in 
d:\oss\nhibernate-trunk\src\NHibernate\AdoNet\ConnectionManager.cs:line 124

   at NHibernate.Impl.SessionImpl.Close() in 
d:\oss\nhibernate-trunk\src\NHibernate\Impl\SessionImpl.cs:line 345

   at 
IDL.Core.Facilities.NServiceBus.MessageModules.UnitOfWorkMessageModule.HandleEndMessage()
 in 
D:\dev\idl-trunk\core\IDL.Core\Facilities\NServiceBus\MessageModules\UnitOfWorkMessageModule.cs:line
 31





What am I doing wrong here?  Is System.Transactions support still too 
experimental to use?



Thanks!



Tyler





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to nhusers@googlegroups.com
To unsubscribe from this group, send email to 
nhusers+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to