EntityFrameworkCore.Cacheable icon indicating copy to clipboard operation
EntityFrameworkCore.Cacheable copied to clipboard

Object reference not set to an instance of an object.

Open coolqingcheng opened this issue 5 years ago • 4 comments

hi,I have a problem with it var smallItems = await _context.posts.Where(a => a.TypeName == item).Take(10).Select(a => new TypeItemDto() { Title = a.Title, TypeName = a.TypeName, Time = a.CreateTime, Id = a.Id }).Cacheable(TimeSpan.FromHours(2)).ToListAsync(); This use will raise an exception :Object reference not set to an instance of an object.

If I remove select,but Using tolist directly is normal

error message: Microsoft.EntityFrameworkCore.Internal.ConcurrencyDetector.EnterCriticalSectionAsync(CancellationToken cancellationToken) Microsoft.EntityFrameworkCore.Query.Internal.AsyncLinqOperatorProvider+ExceptionInterceptor<T>+EnumeratorExceptionInterceptor.MoveNext(CancellationToken cancellationToken) System.Linq.AsyncEnumerable.Aggregate_<TSource, TAccumulate, TResult>(IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, Func<TAccumulate, TResult> resultSelector, CancellationToken cancellationToken) in Aggregate.cs SEOSite.Controllers.ArticlesController.GetTypeList(string type) in ArticlesController.cs + var smallItems = await _context.posts.Where(a => a.TypeName == item).Take(10).Select(a => new TypeItemDto() Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor+TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync() Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync() Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()

coolqingcheng avatar Mar 26 '19 10:03 coolqingcheng

My environment is asp.net core 2.2. I ran your unit test, no problem.But in the ASP.net core environment, inexplicable error. I tried to track the source code, but when cacheResult returned, I reported that the pointer was abnormal. It took four or five hours and hopefully it will solve the problem. It is a pity that I have not been able to solve this problem successfully, but I can only mention issue. I hope you can take the time to solve this problem.

Simple query, basically will not get an error. If the group by and then select such an operation is involved, it is easy to get an error. The driver I use for EFCore is Promelo.EntityFrameworkCore.MySql this library. I don't know if this will have an impact, I'm not familiar with the Expression of Linq. The part that involves CustonQuery, a lot of it can not be read. I'm in Tim issue through the Bing dictionary, and I hope you can read it. Thank you

coolqingcheng avatar Mar 26 '19 14:03 coolqingcheng

I wrote a demo that recreated the error. url: https://share.weiyun.com/5Q84ftF (pass:Y9ST) I uploaded it to the net disk, and this address and password can be downloaded.

coolqingcheng avatar Mar 26 '19 14:03 coolqingcheng

I can confirm, trying this library today, in my first test case .Cachable(TimeSpan.FromMinutes(120)).ToListAsync() and the second run of always hit this exception. What I noticed is if I stepped through it slowly it worked, but if I left my breaks out, I'd hit the above every time, which made it seem to me almost like a race condition was occurring, where cache wasn't populated prior to second run.

RiC0MD avatar May 03 '19 23:05 RiC0MD

Same issue. Working only with ToList sync version.

grinay avatar Aug 02 '19 15:08 grinay