PreDeleteEventListener and InvalidOperationException

12 views
Skip to first unread message

NiHique

unread,
Apr 1, 2009, 11:16:57 AM4/1/09
to nhusers
Hi,

I am using NH 2.1 and custom PreDeleteEventListener (code below).
Listener works, deletes entity, but when I flush session I get this
error

*** Failures ***
System.InvalidOperationException: Collection was modified; enumeration
operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException
(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
at NHibernate.Engine.ActionQueue.ExecuteActions()
at
NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions
(IEventSource session)
at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush
(FlushEvent event)
at NHibernate.Impl.SessionImpl.Flush()


Code for listener is

public class TaskPaneCleanerEventListener :
IPreDeleteEventListener
{
public bool OnPreDelete(PreDeleteEvent e)
{
var taskPaneSource = e.Entity as ITaskPaneSource;
var taskPaneTarget = e.Entity as ITaskPaneTarget;

if (taskPaneSource != null)

HBBCoreServiceLocation.TaskPaneRegister.UnregisterTaskPaneSource
(taskPaneSource);

if (taskPaneTarget != null)

HBBCoreServiceLocation.TaskPaneRegister.UnregisterTaskPaneTarget
(taskPaneTarget);

return false;
}
}

Has anyone faced this problem before?

NiHique

unread,
Apr 1, 2009, 12:57:00 PM4/1/09
to nhusers
It seems like that in PreDeleteEventListener we cannot delete other
entities from session, is this true? If yes, is there any workaround?
Reply all
Reply to author
Forward
0 new messages