Base solution for your next web application
Open Closed

Issues after upgrading to AspNetZero 5.5 #5244


User avatar
0
ajayak created

Note: These issues with aspnet core library updates to 2.1.0

  1. EF Core 2.1.0 Issue: Null Reference exception My Code:
var query = TenantManager.Tenants
                    .Where(c => !c.isA && !c.IsDeleted)
                    .Select(c => new E
                    {
                       X = c.B
                        TenancyName = c.TenancyName
                    })
                    .WhereIf(!input.Filter.IsNullOrEmpty(), c => c.se.Contains(input.Filter))
                    .WhereIf(input.CreatedDaysLessThan.HasValue && input.CreatedDaysLessThan > 0, c => c.DaysSinceRegistered <= input.CreatedDaysLessThan)
                    .WhereIf(input.CreatedDaysMoreThan.HasValue && input.CreatedDaysMoreThan > 0, c => c.DaysSinceRegistered >= input.CreatedDaysMoreThan);

                query =
                    (from q in query
                     join sc in _scRepository.GetAll()
                         .Where(c => c.IsTest != input.HasRealData)
                         .WhereIf(!input.ShowDeleted, c => !c.IsDeleted)
                         .DefaultIfEmpty()
                     on q.TenantId equals sc.TenantId
                     select q).DistinctBy(c => c.TenantId);

                var totalCount = await query.CountAsync();

In my code, the join has 0 result and throws an exception on Count.

Mvc.ExceptionHandling.AbpExceptionFilter - Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.TaskLiftingExpressionVisitor.VisitMember(MemberExpression memberExpression)
   at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
   at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Linq.Expressions.ExpressionVisitor.VisitMemberAssignment(MemberAssignment node)
   at System.Linq.Expressions.ExpressionVisitor.VisitMemberBinding(MemberBinding node)
   at System.Linq.Expressions.ExpressionVisitor.Visit[T](ReadOnlyCollection`1 nodes, Func`2 elementVisitor)
   at System.Linq.Expressions.ExpressionVisitor.VisitMemberInit(MemberInitExpression node)
   at System.Linq.Expressions.MemberInitExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
  1. If you are using NodeServices, don't update to 2.1.0 for now. Below is the exception thrown by working code in 2.0.4.
ERROR 2018-06-14 17:38:38,223 [50   ] ory.Exporting.InventoryReportPdfExporter - The operation was canceled.
System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System.IO.IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request. ---> System.Net.Sockets.SocketException: The I/O operation has been aborted because of either a thread exit or an application request
   --- End of inner exception stack trace ---
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error)
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
   at System.Net.Http.HttpConnection.FillAsync()
   at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean foldedHeadersAllowed)
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   at Microsoft.AspNetCore.NodeServices.HostingModels.HttpNodeInstance.InvokeExportAsync[T](NodeInvocationInfo invocationInfo, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance.InvokeExportAsync[T](CancellationToken cancellationToken, String moduleName, String exportNameOrNull, Object[] args)
   at Microsoft.AspNetCore.NodeServices.NodeServicesImpl.InvokeExportWithPossibleRetryAsync[T](String moduleName, String exportedFunctionName, Object[] args, Boolean allowRetry, CancellationToken cancellationToken)
   at PrimePenguin.Technology.DataExporting.Pdf.PdfExporterBase.CreatePdfPackage(String fileName, String title, String[] headers, List`1 body) in D:\PrimePenguin\PrimePenguin.Service\src\PrimePenguin.Technology.Application\DataExporting\Pdf\PdfExporterBase.cs:line 55
WARN  2018-06-14 17:38:38,412 [68   ] Mvc.ExceptionHandling.AbpExceptionFilter - Failed to generate a downloadable PDF. Please contact admin.
Abp.UI.UserFriendlyException: Failed to generate a downloadable PDF. Please contact admin.
   at PrimePenguin.Technology.DataExporting.Pdf.PdfExporterBase.CreatePdfPackage(String fileName, String title, String[] headers, List`1 body) in D:\PrimePenguin\PrimePenguin.Service\src\PrimePenguin.Technology.Application\DataExporting\Pdf\PdfExporterBase.cs:line 67
   at PrimePenguin.Technology.Reports.Inventory.Exporting.InventoryReportPdfExporter.ExportToFile(List`1 inventoryItemDtos) in D:\PrimePenguin\PrimePenguin.Service\src\PrimePenguin.Technology.Application\Reports\Inventory\Exporting\InventoryReportPdflExporter.cs:line 30
   at PrimePenguin.Technology.Reports.Inventory.InventoryReportAppService.GetInventoryListToPdf(GetInventoryListInput input) in D:\PrimePenguin\PrimePenguin.Service\src\PrimePenguin.Technology.Application\Reports\Inventory\InventoryReportAppService.cs:line 115
   at lambda_method(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()

4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @ajayak have you triedto modify your query ? It might help.

    I'm not sure about the second problem. Using the old version seems fine until it is fixed.

  • User Avatar
    0
    ajayak created

    Hi @ismcagdas,

    The query worked absolutely fine before the upgrade. I will be fixing this query soon to find the real reason of the exception :)

  • User Avatar
    0
    ajayak created

    Hi @ismcagdas,

    I found the cause of the issue. There is an internal error in EF Core 2.1 when using this code for DistinctBy

    public static IQueryable<TSource> DistinctBy<TSource, TKey>(this IQueryable<TSource> source, Expression<Func<TSource, TKey>> keySelector)
            {
                return source.GroupBy(keySelector).Select(x => x.FirstOrDefault());
            }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    @ajayak Thank you for informing us. I'm not sure how to implement this query without DistinctBy, you could try GroupBy.