History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: NEO-62
Type: Bug Bug
Status: Open Open
Priority: Minor Minor
Assignee: Erik Doernenburg
Reporter: Ulu Honolulu
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Neo

System.InvalidOperationException at Neo.Core.ObjectContext.FetchObjectsFromObjectTable

Created: 13/Jun/06 02:23 PM   Updated: 13/Jun/06 02:23 PM
Component/s: Core
Affects Version/s: 1.4.2
Fix Version/s: None

Time Tracking:
Not Specified

Environment: .NET 1.1


 Description  « Hide
This is the exception I get recently:
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.ArrayListEnumeratorSimple.MoveNext()
at Neo.Core.ObjectContext.FetchObjectsFromObjectTable(IFetchSpecification fetchSpec) in d:\ulka\visual studio projects\neo-1.4.0\src\neo\core\objectcontext.cs:line 1331
at Neo.Core.ObjectContext.GetObjects(IFetchSpecification fetchSpec) in d:\ulka\visual studio projects\neo-1.4.0\src\neo\core\objectcontext.cs:line 1259
at Neo.Framework.ObjectFactory.Find(IFetchSpecification fetchSpec) in D:\Ulka\Visual Studio Projects\neo-1.4.0\src\Neo\Framework\ObjectFactory.cs:line 51
at Neo.Framework.ObjectFactory.Find(Qualifier qualifier) in D:\Ulka\Visual Studio Projects\neo-1.4.0\src\Neo\Framework\ObjectFactory.cs:line 57
at Neo.Framework.ObjectFactory.Find(String qualifierFormat, Object[] parameters) in D:\Ulka\Visual Studio Projects\neo-1.4.0\src\Neo\Framework\ObjectFactory.cs:line 63

Here's the scenario: ObjectContext calls FetchObjectsFromStore and retrieves 1 record (which is actually all I need), then it calls FetchObjectsFromObjectTable. While looping through the retrieved objects (in my case 1 object), it evaluates them with the qualifier, which in turn retrieves a property value, which in turn retrieves a RelatedObject (in my case of same type), which in turn calls the database and retrieves a new object. Now the collection of in-memory objects has been modified – Bang!

More specifically, I have a Post object with a ParentPost property (which is also a Post object). I'm trying to retrieve all posts from a specific thread that have some ParentPost. There are two posts in this thread – a parent and a child. Now, FetchObjectsFromStore retrieves the child post, which is what I need. Next, FetchObjectsFromObjectTable has to make sure the ParentPost property is not null. In order to do that, it retrieves the parent post, so the collection we iterate is modified.

Workaround: retrieve all necessary objects before making the search. Performs better too.

So, I guess we could live with the existing situation, and it would suffice to just catch the exception and throw a more meaningful explanation, so that we users don't get puzzled. Could catch the InvalidOperationException, check if objects.Count has been modified. If it has, we have this situation, so throw a Neo exception with a more meaningful explanation and a possible workaround. If it hasn't, rethrow the original exception.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
There are no comments yet on this issue.