VahidN / EFSecondLevelCache.Core

Entity Framework Core Second Level Caching Library
Apache License 2.0
326 stars 51 forks source link

Include functionality giving error #20

Closed sacpi closed 5 years ago

sacpi commented 6 years ago

Summary of the issue

I am using Cacheable in the following manner in Repository to include the entities which are passed but it is giving object ref error after long thinking, I am using it with Redis cache

Environment

The in-use version:
.net core 2.0
ef core 2.1.0 rc1 final
Operating system:  Win 10
IDE: (e.g. Visual Studio 2015)

Example code/Steps to reproduce:

public async Task<IEnumerable<TEntity>> GetAllAsync(params Expression<Func<TEntity, object>>[] includes)
        {
            IQueryable<TEntity> set = dbContext.Set<TEntity>();
            return  (await includes.Aggregate(set, (current, include) => current.Include(include)).Cacheable().ToListAsync() ?? default(IEnumerable<TEntity>));

        }

//Calling

GetAllAsync(b=>b.IncludeEntity1,c=>c.IncludeEntity2)

Output:

Exception message: Object reference not set to an instance of an object.
Full Stack trace:    at System.Text.StringBuilder.Append(String value)
   at System.IO.StringWriter.Write(String value)
   at Newtonsoft.Json.JsonWriter.AutoCompleteClose(JsonContainerType type)
   at Newtonsoft.Json.JsonWriter.AutoCompleteAll()
   at CacheManager.Serialization.Json.JsonCacheSerializer.Serialize[T](T value)
   at CacheManager.Redis.RedisValueConverter.CacheManager.Redis.IRedisValueConverter<System.Object>.ToRedisValue(Object value)
   at CacheManager.Redis.RedisCacheHandle`1.Set(CacheItem`1 item, When when, Boolean sync)
   at CacheManager.Redis.RetryHelper.Retry[T](Func`1 retryme, Int32 timeOut, Int32 retries, ILogger logger)
   at CacheManager.Core.BaseCacheManager`1.AddItemToHandle(CacheItem`1 item, BaseCacheHandle`1 handle)
   at CacheManager.Core.BaseCacheManager`1.AddInternal(CacheItem`1 item)
   at EFCache.EFCacheServiceProvider.InsertValue(String cacheKey, Object value, ISet`1 rootCacheKeys) in <path>\EFCacheServiceProvider.cs:line 77
VahidN commented 5 years ago

I have a lot tests for the Include method here and there is no problem with that.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related problems.