Hello,
A 'Collection was modified; enumeration operation may not execute.' exception has occurred a few times when trying to get the unique result of a query. I haven't been able to replicate this yet..
This seems to be happening deep w/in NHibernate, after it tries to automatically flush the session. For some reason, it fails when printing out the list of entities to the log.
I won't be able to disable log debug mode, so for this specific instance I'm currently considering just switching FlushMode to manual... But I seriously still don't understand how the collection is being modified...
I've been told this same problem happens from time to time elsewhere in the system, e.g. from a CriteriaImp.List<T>.
Any help / suggestions would be appreciated!
Thanks~
Hibernate version:
1.2.1.4000
Name and version of the database you are using:
SQL Server 2005
Code:
Code:
using (NHibernate.ISession session1 = NHibernateSessionManager.Instance.GetSession<DomainRef.FormInstance>(appSession))
{
IQuery q = session1.CreateQuery("FROM FormInstance instance WHERE instance.ReferenceNumber = :ReferenceNumber").SetInt32("ReferenceNumber", referenceNumber);
formInstance = q.UniqueResult<DomainRef.FormInstance>();
}
NHibernate Code:Code:
private void FlushEverything()
{
log.Debug("flushing session");
this.interceptor.PreFlush(this.entitiesByKey.Values);
this.PreFlushEntities();
this.PreFlushCollections();
this.flushing = true;
try
{
this.FlushEntities();
this.FlushCollections();
}
finally
{
this.flushing = false;
}
if (log.IsDebugEnabled)
{
log.Debug(string.Concat(new object[] { "Flushed: ", this.insertions.Count, " insertions, ", this.updates.Count, " updates, ", this.deletions.Count, " deletions to ", this.entityEntries.Count, " objects" }));
log.Debug(string.Concat(new object[] { "Flushed: ", this.collectionCreations.Count, " (re)creations, ", this.collectionUpdates.Count, " updates, ", this.collectionRemovals.Count, " removals to ", this.collectionEntries.Count, " collections" }));
new Printer(this.factory).ToString(this.entitiesByKey.Values.GetEnumerator()); /////dies here
}
}
Full stack trace of any exception that occurs:
System.Exception: Service Name:
'....Form.GetFormDefinitionVersionByReferenceNumberFullService' ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Hashtable.HashtableEnumerator.MoveNext()
at NHibernate.Impl.Printer.ToString(IEnumerator enumerator)
at NHibernate.Impl.SessionImpl.FlushEverything()
at NHibernate.Impl.SessionImpl.AutoFlushIfRequired(ISet querySpaces)
at NHibernate.Impl.SessionImpl.GetQueries(String query, Boolean scalar)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters, IList results)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
at NHibernate.Impl.QueryImpl.List()
at NHibernate.Impl.AbstractQueryImpl.UniqueResult()
at NHibernate.Impl.AbstractQueryImpl.UniqueResult[T]()
at ...Form.GetFormDefinitionVersionByReferenceNumberFull.RetrieveFormDefinitionVersionByReferenceNumber(Int32 referenceNumber, AppSession appSession) in D:\...GetFormDefinitionVersionByReferenceNumberFull.cs:line 44