Null Reference Error when trying to add a product to order
I've taken code from the example site and applied it in mine but keep getting this error whenever I try to add an item to the cart.
I've tweaked the code to have a hardcoded product just to test the snippet but it's still in a surface controller. The weird part is that the code works when I debug, add a break point on the erroring line and inspect order. After that the code works fine, it adds the product and creates the order no problem.
at Vendr.Core.Calculators.OrderLineCalculator.CalculateOrderLineUnitPrice(OrderReadOnly order, OrderLineReadOnly orderLine, Guid currencyId, TaxRate taxRate)
at Vendr.Core.Pipelines.OrderLine.Tasks.CalculateOrderLineUnitPriceWithoutDiscountsTask.Execute(OrderLineCalculationPipelineArgs args)
at Vendr.Core.Pipelines.PipelineTaskWithTypedArgsBase`2.Execute(PipelineArgs`1 args)
at Vendr.Core.Pipelines.PipelineTaskBase`2.Execute(PipelineArgs input)
at Vendr.Core.Pipelines.InProcPipelineInvoker.<Vendr.Core.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )
at Vendr.Core.Pipelines.InProcPipelineInvoker.<Vendr.Core.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )
at Vendr.Core.Pipelines.InProcPipelineInvoker.Vendr.Core.Pipelines.IPipelineInvoker.Invoke(IEnumerable`1 pipelineTasks, PipelineArgs args)
at Vendr.Core.Pipelines.Pipeline.Invoke[TPipeline,TArgs,TEntity](Func`2 argsFactory)
at Vendr.Core.Pipelines.Order.Tasks.OrderLinesCalculationPipelineTaskBase`1.Execute(OrderCalculationPipelineArgs args)
at Vendr.Core.Pipelines.PipelineTaskWithTypedArgsBase`2.Execute(PipelineArgs`1 args)
at Vendr.Core.Pipelines.PipelineTaskBase`2.Execute(PipelineArgs input)
at Vendr.Core.Pipelines.InProcPipelineInvoker.<Vendr.Core.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )
at Vendr.Core.Pipelines.InProcPipelineInvoker.Vendr.Core.Pipelines.IPipelineInvoker.Invoke(IEnumerable`1 pipelineTasks, PipelineArgs args)
at Vendr.Core.Pipelines.Pipeline.Invoke[TPipeline,TArgs,TEntity](Func`2 argsFactory)
at Vendr.Core.Pipelines.SubPipelineTaskBase`2.Execute(PipelineArgs`1 input)
at Vendr.Core.Pipelines.PipelineTaskBase`2.Execute(PipelineArgs input)
at Vendr.Core.Pipelines.InProcPipelineInvoker.<Vendr.Core.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )
at Vendr.Core.Pipelines.InProcPipelineInvoker.<Vendr.Core.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )
at Vendr.Core.Pipelines.InProcPipelineInvoker.<Vendr.Core.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )
at Vendr.Core.Pipelines.InProcPipelineInvoker.Vendr.Core.Pipelines.IPipelineInvoker.Invoke(IEnumerable`1 pipelineTasks, PipelineArgs args)
at Vendr.Core.Pipelines.Pipeline.Invoke[TPipeline,TArgs,TEntity](Func`2 argsFactory)
at Vendr.Core.Calculators.OrderCalculator.CalculateOrder(OrderReadOnly order)
at Vendr.Core.Models.Order.Recalculate(Boolean force, IOrderCalculator orderCalculator)
at Vendr.Core.Models.Order.Recalculate(IOrderCalculator orderCalculator)
at Vendr.Core.OrderExtensions.Recalculate(Order order)
at Vendr.Core.Services.OrderService.SaveOrder(Order entity)
at MyCoolSite.Core.Controllers.Surface.CartSurfaceController.AddToCart(String productReference) in C:\Sites\MyCoolSite\MyCoolSite\MyCoolSite.Core\Controllers\Surface\CartSurfaceController.cs:line 49
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()
I was playing around and ended up deleting and creating a few new stores and seems changing the store resets the prices. I knew I had something similar working yesterday.
Null Reference Error when trying to add a product to order
I've taken code from the example site and applied it in mine but keep getting this error whenever I try to add an item to the cart.
I've tweaked the code to have a hardcoded product just to test the snippet but it's still in a surface controller. The weird part is that the code works when I debug, add a break point on the erroring line and inspect
order. After that the code works fine, it adds the product and creates the order no problem.Hi Mark,
What version of Vendr are you using?
/Matt
Hey Matt,
At the time of writing it was 1.1.3 but I've just updated to 1.1.4 and seeing the same results
Hmm, do you have a price defined on your product for the orders given currency?
That was it!
I was playing around and ended up deleting and creating a few new stores and seems changing the store resets the prices. I knew I had something similar working yesterday.
Thank you very much
No problem.
I'll still go add it as a bug on our issue tracker as we ultimately have some code that isn't performing a null check.
Thanks for reporting it and glad we could get you working 👍
/Matt
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.