Clear on EntityCollection fails with error

Posts   
 
    
Meindert
User
Posts: 63
Joined: 07-Nov-2012
# Posted on: 28-Sep-2018 08:24:30   

LLBLGen runtime version 5.1.1

When I clear a pre-fetched detail collection, before the (re)fetch details, of a particular entity I become an exception: "Collection was modified; enumeration operation may not execute" (stack trace below)

Hoe can I find the cause of the problem? I know that clear is different then RemoveAt construction.

Fail code:

aDrawingSet.EplanWiringDiagramVersions.Clear();

Working code:


                try
                {
                    for (int idx = aDrawingSet.EplanWiringDiagramVersions.Count - 1; idx >= 0; idx--)
                        aDrawingSet.EplanWiringDiagramVersions.RemoveAt(idx);
                }
                catch (Exception ex)
                {
                    int aap = 2;
                }

stack trace:

At EDBDataStore.cs:line 997: aDrawingSet.EplanWiringDiagramVersions.Clear();


StackTrace
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at SD.LLBLGen.Pro.ORMSupportClasses.CollectionCore`1.Clear() in C:\Myprojects\VS.NET Projects\LLBLGen Pro v5.1\Frameworks\LLBLGen Pro\RuntimeLibraries\ORMSupportClasses\Core\CollectionCore.cs:line 412
   at CATENA.EDBDataStore.FetchEplanWiringDiagramVersion(DrawingSetsEntity aDrawingSet) in C:\Projecten\CATENA_Client_SVN\CATENA\Classes\EDBDataStore.cs:line 997
   at CATENA.DataControllers.DrawingSetsDetailed.GenerateContent() in C:\Projecten\CATENA_Client_SVN\CATENA\Classes\DataControllers\DrawingSetsDetailed.cs:line 790

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39613
Joined: 17-Aug-2003
# Posted on: 28-Sep-2018 08:46:18   

llblgen runtime version ?

Frans Bouma | Lead developer LLBLGen Pro
Meindert
User
Posts: 63
Joined: 07-Nov-2012
# Posted on: 28-Sep-2018 10:17:09   

Runtime version added to the original post

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 28-Sep-2018 11:16:14   

Could you please test with an EntityCollection not bound to any UI control? If you still get the exception, please test with v.5.4

I can't reproduce it with the following code:

var customres = new EntityCollection<CustomerEntity> ();
var prefetch = new PrefetchPath2(EntityType.CustomerEntity);
prefetch.Add(CustomerEntity.PrefetchPathOrders).SubPath.Add(OrderEntity.PrefetchPathOrderDetails);

using (var adapter = new DataAccessAdapter())
{
    adapter.FetchEntityCollection(customres, null, prefetch);
}

customres.Clear();

If you still get the exception, please provide the simplest possible repro, preferably on Northwind.

Thanks,