Print Page | Close Window

InvalidOperation Exception when saving

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2413
Printed Date: 16-Jun-2026 at 5:49pm


Topic: InvalidOperation Exception when saving
Posted By: mmedic
Subject: InvalidOperation Exception when saving
Date Posted: 02-Jan-2011 at 9:59pm
I have a Book object in my model that contains a list of Isbn objects. When I try to delete a whole graph of Book (including the Isbn object), I get a "RelatedEntityList's are not reentrant" message. I've never seen that before and could not dig up anything on the net. Any ideas why this error is occurring?



Replies:
Posted By: DenisK
Date Posted: 03-Jan-2011 at 11:21am
Hi mmedic;

Could you provide a repro solution using NorthwindIB database? Thank you.


Posted By: mmedic
Date Posted: 03-Jan-2011 at 11:33am
I am not sure that I'll be able to recreate it using the NorthwindIB database. I'm trying to get information on what this exception means as it may be something I'm doing wrong in my code. I could not find any documentation about the exception or concept or reentrance. The method throwing the exception is CheckReenatrance().


Posted By: DenisK
Date Posted: 03-Jan-2011 at 3:34pm
mmedic;

I've tried to repro but was not able to as well. Here's what reentrant means from Wikipedia. 

http://en.wikipedia.org/wiki/Reentrant_%28subroutine%29 - http://en.wikipedia.org/wiki/Reentrant_(subroutine)

In the context of this issue, this exception can occur if you have a RelatedEntityList<T> and you are making a change to that list using either Clear(), Add(), Remove() and/or RemoveAt() methods. And while that change is still being made, another change is executed.

In your case, you have a Book with a RelatedEntityList<Isbn>. My suggestion is to check whether there's another Add, Clear, and/or Remove operation that is being executed while you're deleting the Book's object graph.

Hope this helps.


Posted By: mmedic
Date Posted: 03-Jan-2011 at 6:18pm
I looked at this some more and actually the error is happening when I call Entity.Delete() method as a part of deleting the object graph. There is noting that is modifying the collection at tha time but the collection was bound to an Infragtistics DataGrid and unbound prior to Delete() call. Any ideas?


Posted By: DenisK
Date Posted: 03-Jan-2011 at 6:31pm
Could you try deleting the object graph without binding the collection to the Infragistics DataGrid in the first place?


Posted By: mmedic
Date Posted: 03-Jan-2011 at 8:14pm
I think I figured it out. I was trying to delete an object graph in the collection changed event handler which did not work. Once I moved the Delete() outside the event handler code, everything worked OK. Thanks for your help!


Posted By: DenisK
Date Posted: 04-Jan-2011 at 1:23am
No problem. Thanks for sharing your solution.



Print Page | Close Window