System.InvalidOperationException at Neo.Core.ObjectContext.FetchObjectsFromObjectTable
--------------------------------------------------------------------------------------
Key: NEO-62
URL:
http://jira.codehaus.org/browse/NEO-62 Project: Neo
Type: Bug
Components: Core
Versions: 1.4.2
Environment: .NET 1.1
Reporter: Ulu Honolulu
Assigned to: Erik Doernenburg
Priority: Minor
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.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa-
For more information on JIRA, see:
http://www.atlassian.com/software/jira---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email