tags:

views:

144

answers:

1

Hi, I have a multithreaded NHibernate application with ThreadStaticSessionContext. I bind un each thread a new session. Before exiting the thread I commit the transaction and i get

enumerator was modified

  at NHibernate.Util.SequencedHashMap.OrderedEnumerator.MoveNext()  
  at NHibernate.Util.IdentityMap.get_EntryList()  
  at NHibernate.Util.IdentityMap.ConcurrentEntries(IDictionary map)  
  at NHibernate.Event.Default.AbstractFlushingEventListener.PrepareEntityFlushes(IEventSource session)  
  at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event)  
  at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)  
  at NHibernate.Impl.SessionImpl.Flush()  
  at NHibernate.Transaction.AdoTransaction.Commit()  
  at ...

I don't have a clue...

+1  A: 

This exception is usually thrown when you add/remove from a collection while it is being enumerated (like in a foreach statement).

Richard Szalay
The code fails in try { Transaction.Commit(); Session.Close(); return true; } catch( Exception ex ) { //log ex Console.WriteLine( ex ); Console.ReadKey(); if( Transaction != null ) Transaction.Rollback(); if( Session != null ) Session.Clear(); return false; }in Transaction.Commit()
DaeMoohn
It looks like the collection is being modified by another thread during the `Commit`
Richard Szalay
Thanks for the hint, I'll start checking...
DaeMoohn
I had a bug which broke my assumption of one ISession per thread...
DaeMoohn
It sounded like a multithreading issue. Glad you fixed it.
Richard Szalay