Neo

System.InvalidOperationException at Neo.Core.ObjectContext.FetchObjectsFromObjectTable

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.4.2
  • Fix Version/s: None
  • Component/s: Core
  • Labels:
    None
  • Environment:
    .NET 1.1
  • Number of attachments :
    0

Description

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.

Activity

There are no comments yet on this issue.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: