NullReferenceException on FetchEntityCollection

Posts   
 
    
Kiltux
User
Posts: 25
Joined: 19-Sep-2013
# Posted on: 27-May-2014 10:28:42   

Hey SD,

I have an issue with Fetching an Entity Collection when using Parallel processing, although the piece of code should be executed single threaded.

This is my code, the parameters that i pass to FetchEntityCollection are all not null



private T FetchEntity(params object[] parameters)
{
    RelationPredicateBucket bucket = new RelationPredicateBucket();
    for (int i = 0; i < this.KeyFields.Count; i++)
        bucket.PredicateExpression.AddWithAnd(this.KeyFields[i] == parameters[i]);

    if (this.CacheBucketFilter != null)
    {
        foreach (EntityRelation relation in this.CacheBucketFilter.Relations)
            bucket.Relations.Add(relation, JoinHint.Left);
    }

    EntityCollection<T> entities = new EntityCollection<T>();
    //The adapter is always new and opened
    AdapterManager.Adapter.FetchEntityCollection(entities, bucket, this.CachePrefetchPath); // <-- Getting a null reference exception

    T entity = entities.FirstOrDefault();
    if (entity != null)
        this.AddToCache(entity);

    return entity;
}


When i dig deeper i find that a parameter passed in your function is null, this is a piece of code in the PersistenceCore



internal static IEntityCore FindPkObject(Dictionary<int, List<IEntityCore>> parentSideHashes, int childHash, IList childSideFields, IList pkSideFields)
{
    IEntityCore toReturn = null;

    if(!parentSideHashes.ContainsKey(childHash)) // <-- Comming from here in PresistenceCore, parentSideHashes is null
    {
        // not there
        return toReturn;
    }

    ........
}


But if i look at the calling function MergeNormal then it should not be possible that null gets passed in as a parameter. So i'm a bit lost why this is happening.

It looks like a parallel problem, but in the function where i call the FetchEntityCollection, everything is initiated in the function, so in my logic it can't be a parallel problem, except if the EntityCollection gets cached somewhere else than the adapter.

I Hope you can shed some light at the problem, i have attached an image with 2 printscreens, one with some variables that may be helpfull and one where the exception occures.

I use LLBLGen 4.0, and .net framework 4.0

Attachments
Filename File size Added on Approval
CombinedImage.png 130,903 27-May-2014 10:28.59 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 27-May-2014 14:48:21   

Please confirm you use the latest v4.0 build. http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7717

Frans Bouma | Lead developer LLBLGen Pro
Kiltux
User
Posts: 25
Joined: 19-Sep-2013
# Posted on: 27-May-2014 14:56:40   

I have LLBLGen version 4.0.13.1015

Attachments
Filename File size Added on Approval
LLBLGen version.png 30,424 27-May-2014 14:57.16 Approved
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 27-May-2014 16:03:57   

Please download the latest build from the customer area to make sure you're using the latest runtime library.

Frans Bouma | Lead developer LLBLGen Pro
Kiltux
User
Posts: 25
Joined: 19-Sep-2013
# Posted on: 27-May-2014 17:00:32   

It seems to have worked, but i'll investigate it a little bit further tomorrow.

Posts: 2
Joined: 08-Oct-2018
# Posted on: 08-Oct-2018 10:04:41   
  public void FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, int maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath);

return null in collectionToFill if there exist multi thread(huge request count in same time for same database record). llblgen pro version: 5.0.0.0 Runtime version: v4.0.30319

What can call the problem?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 08-Oct-2018 10:27:26   

Please don't append to existing threads with a new problem so start a new topic instead, please provide a stacktrace otherwise the exception is of no use, please try with the latest build within the version you have (5.0.0.0 is the first release, try at least 5.0.10), and with multi-threaded issues, make absolutely sure you're not sharing adapter instances or query elements like predicates etc.

Frans Bouma | Lead developer LLBLGen Pro