Upgrade to 4.40 and the Cart not working

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 года назад
Hi Guy,

Can someone help me out?

System.NullReferenceException: Object reference not set to an instance of an object.
   at Nop.Services.Orders.OrderTotalCalculationService.GetShoppingCartShippingTotalAsync(IList`1 cart, Boolean includingTax) in

Thanks.
3 года назад
Where is this error occouring - in the core  ?
Or are you making a plugin and calling the GetShoppingCartShippingTotalAsync routine ?
Is there more details in the dump in the Log file ?
3 года назад
Hi Yinda,

This happened when I added item to the cart, the error page came out. Below is the full log file.

System.NullReferenceException: Object reference not set to an instance of an object.
   at Nop.Services.Orders.OrderTotalCalculationService.GetShoppingCartShippingTotalAsync(IList`1 cart, Boolean includingTax) in C:\Users\Mark\Downloads\nopCommerce_4.40_Source (1)\src\Libraries\Nop.Services\Orders\OrderTotalCalculationService.cs:line 1101
   at Nop.Services.Orders.OrderTotalCalculationService.GetShoppingCartShippingTotalAsync(IList`1 cart) in C:\Users\Mark\Downloads\nopCommerce_4.40_Source (1)\src\Libraries\Nop.Services\Orders\OrderTotalCalculationService.cs:line 1044
   at Nop.Web.Factories.ShoppingCartModelFactory.PrepareOrderTotalsModelAsync(IList`1 cart, Boolean isEditable) in C:\Users\Mark\Downloads\nopCommerce_4.40_Source (1)\src\Presentation\Nop.Web\Factories\ShoppingCartModelFactory.cs:line 1136
   at Nop.Web.Components.OrderTotalsViewComponent.InvokeAsync(Boolean isEditable) in C:\Users\Mark\Downloads\nopCommerce_4.40_Source (1)\src\Presentation\Nop.Web\Components\OrderTotals.cs:line 34
   at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.InvokeAsyncCore(ObjectMethodExecutor executor, ViewComponentContext context)
   at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.InvokeAsync(ViewComponentContext context)
   at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper.InvokeCoreAsync(ViewComponentDescriptor descriptor, Object arguments)
   at AspNetCore.Views_Shared_Components_OrderSummary_Default.<ExecuteAsync>b__14_0() in D:\home\site\wwwroot\Views\Shared\Components\OrderSummary\Default.cshtml:line 255
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperExecutionContext.GetChildContentAsync(Boolean useCachedResult, HtmlEncoder encoder)
   at Microsoft.AspNetCore.Mvc.TagHelpers.RenderAtEndOfFormTagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, Int32 i, Int32 count)
   at AspNetCore.Views_Shared_Components_OrderSummary_Default.ExecuteAsync() in D:\home\site\wwwroot\Views\Shared\Components\OrderSummary\Default.cshtml:line 17
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewComponents.ViewViewComponentResult.ExecuteAsync(ViewComponentContext context)
   at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentInvoker.InvokeAsync(ViewComponentContext context)
   at Microsoft.AspNetCore.Mvc.ViewComponents.DefaultViewComponentHelper.InvokeCoreAsync(ViewComponentDescriptor descriptor, Object arguments)
   at AspNetCore.Views_ShoppingCart_Cart.ExecuteAsync() in D:\home\site\wwwroot\Views\ShoppingCart\Cart.cshtml:line 19
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ActionContext actionContext, IView view, ViewDataDictionary viewData, ITempDataDictionary tempData, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
   at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultFilters>g__Awaited|27_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at WebMarkupMin.AspNetCore5.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, Boolean useMinification, Boolean useCompression)
   at WebMarkupMin.AspNetCore5.WebMarkupMinMiddleware.ProcessAsync(HttpContext context, Boolean useMinification, Boolean useCompression)
   at WebMarkupMin.AspNetCore5.WebMarkupMinMiddlewareBase.Invoke(HttpContext context)
   at StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in C:\projects\dotnet\src\MiniProfiler.AspNetCore\MiniProfilerMiddleware.cs:line 104
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Nop.Services.Authentication.AuthenticationMiddleware.InvokeAsync(HttpContext context) in C:\Users\Mark\Downloads\nopCommerce_4.40_Source (1)\src\Libraries\Nop.Services\Authentication\AuthenticationMiddleware.cs:line 94
   at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.<Invoke>g__AwaitMatch|8_1(EndpointRoutingMiddleware middleware, HttpContext httpContext, Task matchTask)
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Nop.Services.Installation.InstallUrlMiddleware.InvokeAsync(HttpContext context, IWebHelper webHelper) in C:\Users\Mark\Downloads\nopCommerce_4.40_Source (1)\src\Libraries\Nop.Services\Installation\InstallUrlMiddleware.cs:line 52
   at Nop.Services.Common.KeepAliveMiddleware.InvokeAsync(HttpContext context, IWebHelper webHelper) in C:\Users\Mark\Downloads\nopCommerce_4.40_Source (1)\src\Libraries\Nop.Services\Common\KeepAliveMiddleware.cs:line 49
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.<Invoke>g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
2 года назад
liudengme wrote:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Nop.Services.Orders.OrderTotalCalculationService.GetShoppingCartShippingTotalAsync(IList`1 cart, Boolean includingTax) in C:\Users\Mark\Downloads\nopCommerce_4.40_Source (1)\src\Libraries\Nop.Services\Orders\OrderTotalCalculationService.cs:line 1101
  


Here is line 1101: https://github.com/nopSolutions/nopCommerce/blob/89113781d5e73214be62bd02be05f45f6766ef30/src/Libraries/Nop.Services/Orders/OrderTotalCalculationService.cs#L1101

It looks like you may have 1x Shipping Rate Computation Method defined, but no associated fixed rates defined for that method.  Check that your shipping rate plugin was upgraded correctly and has appropriate methods/rates defined.  

Or it may be catching the null reference on shippingOptionRequests but I wouldn't think it would drop into the foreach loop if that was null.  Hard to say for sure without stepping through with the debugger.
2 года назад
Thanks for reply.

I only have UPS setup as the shipping method.
2 года назад
Looks like I have to add the fixed shipping rate plugin.
2 года назад
liudengme wrote:
Thanks for reply.

I only have UPS setup as the shipping method.


Are you using nopCommerce's default UPS plugin and you have at least 1 of its services checked in the plugin configuration?  It returns a nullable decimal for GetFixedRateAsync (which is different than your null object reference error) :
https://github.com/nopSolutions/nopCommerce/blob/a298e6a29fd0cc130257afdca8f44bd4752cfead/src/Plugins/Nop.Plugin.Shipping.UPS/UPSComputationMethod.cs#L77

Do you have Visual Studio and the ability to debug the code?  At this point I would be setting breakpoints in that method to see exactly what object is null.  It could be a shipping address?
2 года назад
You don't have to "add the fixed shipping rate plugin" if you are using UPS.  Just don't expect to get rates shown in the Shopping Cart.    In the shopping cart page, if there is only one Active shipping rate plugin, then nopCommerce will call/check to see if it returns a rate.  UPS does not support "Fixed Rates" (it needs to get rates form the API call to UPS), so it returns null.  But that's OK, the code check for it:
if (!fixedRateTmp.HasValue)
    continue;

It works fine for me.  Did you customize OrderTotalCalculationService.GetShoppingCartShippingTotalAsync, and thus your "line 1101" is not the call to GetFixedRateAsync?

(Did you get the latest version 4.40.3 ?)
2 года назад
I haven't upgraded to 4.40.3. Let me try to upgrade see what happen.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.