{"record":{"id":"00301842c2ecc1ca","repo":"nopSolutions/nopCommerce","slug":"address-can-t-be-loaded","errorCode":null,"errorMessage":"Address can't be loaded","messagePattern":"Address can't be loaded","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"src/Presentation/Nop.Web/Controllers/CheckoutController.cs","lineNumber":288,"sourceCode":"        try\r\n        {\r\n            if (!ModelState.IsValid)\r\n            {\r\n                var errors = string.Join(\", \", ModelState.Values.Where(p => p.Errors.Any()).SelectMany(p => p.Errors)\r\n                    .Select(p => p.ErrorMessage));\r\n\r\n                throw new Exception(errors);\r\n            }\r\n\r\n            var customer = await _workContext.GetCurrentCustomerAsync();\r\n            var store = await _storeContext.GetCurrentStoreAsync();\r\n            var cart = await _shoppingCartService.GetShoppingCartAsync(customer, ShoppingCartType.ShoppingCart, store.Id);\r\n            if (!cart.Any())\r\n                throw new Exception(\"Your cart is empty\");\r\n\r\n            //find address (ensure that it belongs to the current customer)\r\n            var address = await _customerService.GetCustomerAddressAsync(customer.Id, addressModel.Id)\r\n                          ?? throw new Exception(\"Address can't be loaded\");\r\n\r\n            //custom address attributes\r\n            var customAttributes = await _addressAttributeParser.ParseCustomAttributesAsync(form, NopCommonDefaults.AddressAttributeControlName);\r\n            var customAttributeWarnings = await _addressAttributeParser.GetAttributeWarningsAsync(customAttributes);\r\n\r\n            if (customAttributeWarnings.Any())\r\n                return Json(new { error = 1, message = customAttributeWarnings });\r\n\r\n            address = addressModel.ToEntity(address);\r\n            address.CustomAttributes = customAttributes;\r\n\r\n            await _addressService.UpdateAddressAsync(address);\r\n\r\n            return await getResult(customer, cart, address);\r\n        }\r\n        catch (Exception exc)\r\n        {\r\n            await _logger.WarningAsync(exc.Message, exc, await _workContext.GetCurrentCustomerAsync());\r","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Presentation/Nop.Web/Controllers/CheckoutController.cs#L270-L306","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Refresh the address list and edit a currently-valid address id.","Ensure the address was not deleted in another session/tab before submitting.","Return a clear 'address no longer available' JSON and let the customer re-select.","Validate addressModel.Id belongs to the customer before opening the editor."],"exampleFix":"// before\nvar address = await _customerService.GetCustomerAddressAsync(customer.Id, addressModel.Id)\n    ?? throw new Exception(\"Address can't be loaded\");\n// after (localized message)\nvar address = await _customerService.GetCustomerAddressAsync(customer.Id, addressModel.Id);\nif (address is null)\n    throw new Exception(await _localizationService.GetResourceAsync(\"Checkout.AddressNotFound\"));","handlingStrategy":"validation","validationCode":"// Confirm the address belongs to the customer before editing.\nvar address = await _customerService.GetCustomerAddressAsync(customer.Id, addressModel.Id);\nif (address is null)\n    return Json(new { error = 1, message = \"Address is no longer available.\" });","typeGuard":"static bool AddressOwned(Address a) => a is not null;","tryCatchPattern":"// Wrapped by EditAddressAsync catch returning JSON error.\ncatch (Exception exc) { return Json(new { error = 1, message = exc.Message }); }","preventionTips":["Validate addressModel.Id belongs to the customer before opening the editor.","Handle the 'deleted in another tab' race.","Refresh the address list before editing if the page was open a long time."],"tags":["nopcommerce","checkout","address","not-found","ownership","session"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}