Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object reference not set to an instance of an object. #9

Open
coolqingcheng opened this issue Mar 26, 2019 · 4 comments
Open

Object reference not set to an instance of an object. #9

coolqingcheng opened this issue Mar 26, 2019 · 4 comments

Comments

@coolqingcheng
Copy link

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
Copy link
Author

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
Copy link
Author

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.

@RiC0MD
Copy link

RiC0MD commented May 3, 2019

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.

@grinay
Copy link

grinay commented Aug 2, 2019

Same issue. Working only with ToList sync version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants