Skip to content

Error when calling GetOrCreateCurrentOrderAsync after upgrading from v14 to v15 #715

@jwolke

Description

@jwolke

Which component is this issue related to?

Umbraco Commerce (Core)

Which Umbraco Commerce version are you using? (Please write the exact version, example: 10.1.0)

15.3.4

Bug summary

I recently upgraded from v14.1.5 to v15.4.1 of Umbraco Commerce and I am running into an issue in the CartSurfaceController code that I copied from the Demo Store. I am encountering the following error on this line of code:

var order = await _commerceApi.GetOrCreateCurrentOrderAsync(store.Id) .AsWritableAsync(uow);

Error:

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Umbraco.Commerce.Web
StackTrace:
at Umbraco.Commerce.Web.Session.CookieSessionStore.GetValue[T](String key)
at Umbraco.Commerce.Core.Session.SessionManager.<>c__DisplayClass43_0.<b__0>d.MoveNext()
at Umbraco.Commerce.Core.Session.SessionManager.d__1011.MoveNext() at Umbraco.Commerce.Core.Session.SessionManager.<>c__DisplayClass56_0.<<GetDefaultShippingMethodAsync>b__0>d.MoveNext() at Umbraco.Commerce.Core.Session.SessionManager.<WithSessionStoreAsync>d__1011.MoveNext()
at Umbraco.Commerce.Core.Session.SessionManager.<>c__DisplayClass14_0.<b__1>d.MoveNext()
at Umbraco.Commerce.Core.UmbracoCommerceUnitOfWorkProvider.d__221.MoveNext() at Umbraco.Commerce.Core.UmbracoCommerceUnitOfWorkProvider.<ExecuteWithUnitOfWorkAsync>d__221.MoveNext()
at Umbraco.Commerce.Core.Session.SessionManager.d__14.MoveNext()
at Umbraco.Commerce.Core.Session.SessionManager.d__13.MoveNext()
at Umbraco.Commerce.Extensions.AggregateBaseExtensions.d__7.MoveNext()
at GeneTools.Core.Web.Controllers.CartSurfaceController.<>c__DisplayClass2_0.<b__0>d.MoveNext() in C:\dev\genetools\src\GeneTools.Core\Web\Controllers\CartSurfaceController.cs:line 36

This exception was originally thrown at this call stack:
[External Code]
GeneTools.Core.Web.Controllers.CartSurfaceController.AddToCart.AnonymousMethod__0(Umbraco.Commerce.Common.IUnitOfWork) in CartSurfaceController.cs

We are using the same code as the demo store. Based on my debugging, the error seems to happen in the GetCurrentAdminOrderAsync() method of the Umbraco.Commerce.Core.Session::SessionManager.cs class

When I switch to using the Result rather than awaiting the call to GetOrCreateCurrentOrderAsync, everything works as expected:

var order = _commerceApi.GetOrCreateCurrentOrderAsync(store.Id).AsWritableAsync(uow).Result;

Specifics

No response

Steps to reproduce

TBD

Expected result / actual result

No response

Dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions