nopSolutions/nopCommerce · warning · Exception

Address can't be loaded

Error message

Address can't be loaded

What it means

Thrown in EditAddressAsync when GetCustomerAddressAsync(customer.Id, addressModel.Id) returns null — i.e., the address id in the edit form does not belong to the current customer (or no longer exists). The null-coalescing throw produces Exception("Address can't be loaded"), caught at line 304 and returned as JSON. It guards against a customer editing an address id they do not own.

Source

Thrown at src/Presentation/Nop.Web/Controllers/CheckoutController.cs:288

        try
        {
            if (!ModelState.IsValid)
            {
                var errors = string.Join(", ", ModelState.Values.Where(p => p.Errors.Any()).SelectMany(p => p.Errors)
                    .Select(p => p.ErrorMessage));

                throw new Exception(errors);
            }

            var customer = await _workContext.GetCurrentCustomerAsync();
            var store = await _storeContext.GetCurrentStoreAsync();
            var cart = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.ShoppingCart, store.Id);
            if (!cart.Any())
                throw new Exception("Your cart is empty");

            //find address (ensure that it belongs to the current customer)
            var address = await _customerService.GetCustomerAddressAsync(customer.Id, addressModel.Id)
                          ?? throw new Exception("Address can't be loaded");

            //custom address attributes
            var customAttributes = await _addressAttributeParser.ParseCustomAttributesAsync(form, NopCommonDefaults.AddressAttributeControlName);
            var customAttributeWarnings = await _addressAttributeParser.GetAttributeWarningsAsync(customAttributes);

            if (customAttributeWarnings.Any())
                return Json(new { error = 1, message = customAttributeWarnings });

            address = addressModel.ToEntity(address);
            address.CustomAttributes = customAttributes;

            await _addressService.UpdateAddressAsync(address);

            return await getResult(customer, cart, address);
        }
        catch (Exception exc)
        {
            await _logger.WarningAsync(exc.Message, exc, await _workContext.GetCurrentCustomerAsync());

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Refresh the address list and edit a currently-valid address id.
  2. Ensure the address was not deleted in another session/tab before submitting.
  3. Return a clear 'address no longer available' JSON and let the customer re-select.
  4. Validate addressModel.Id belongs to the customer before opening the editor.

Example fix

// before
var address = await _customerService.GetCustomerAddressAsync(customer.Id, addressModel.Id)
    ?? throw new Exception("Address can't be loaded");
// after (localized message)
var address = await _customerService.GetCustomerAddressAsync(customer.Id, addressModel.Id);
if (address is null)
    throw new Exception(await _localizationService.GetResourceAsync("Checkout.AddressNotFound"));
Defensive patterns

Strategy: validation

Validate before calling

// Confirm the address belongs to the customer before editing.
var address = await _customerService.GetCustomerAddressAsync(customer.Id, addressModel.Id);
if (address is null)
    return Json(new { error = 1, message = "Address is no longer available." });

Type guard

static bool AddressOwned(Address a) => a is not null;

Try / catch

// Wrapped by EditAddressAsync catch returning JSON error.
catch (Exception exc) { return Json(new { error = 1, message = exc.Message }); }

Prevention

When it happens

Trigger: The posted addressModel.Id has no matching row in the customer's address book (CustomerAddress mapping). Triggered by a stale address id, an address deleted in another tab, a tampered form, or a guest-to-registered conversion where address book ids changed.

Common situations: Address deleted by the customer/admin between page load and edit submit; multi-tab checkout where one tab removes the address; form tampering to access another customer's address id; address book rebuilt after account merge leaving old ids invalid.

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/00301842c2ecc1ca. Report an issue: GitHub.