{"record":{"id":"784035c9cc2ea5a2","repo":"nopSolutions/nopCommerce","slug":"shipping-is-required-but-address-is-not-available","errorCode":null,"errorMessage":"Shipping is required, but address is not available. Order ID = {order.Id}","messagePattern":"Shipping is required, but address is not available\\. Order ID = (.+?)","errorType":"exception","errorClass":"NopException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/Common/PdfService.cs","lineNumber":265,"sourceCode":"        return (fontName, fontSize);\r\n    }\r\n\r\n    /// <summary>\r\n    /// Get shipping address\r\n    /// </summary>\r\n    /// <param name=\"lang\">Language</param>\r\n    /// <param name=\"order\">Order</param>\r\n    /// <returns>A task that contains address item</returns>\r\n    protected virtual async Task<AddressItem> GetShippingAddressAsync(Language lang, Order order)\r\n    {\r\n        var addressResult = new AddressItem();\r\n\r\n        if (order.ShippingStatus != ShippingStatus.ShippingNotRequired)\r\n        {\r\n            if (!order.PickupInStore)\r\n            {\r\n                if (order.ShippingAddressId == null || await _addressService.GetAddressByIdAsync(order.ShippingAddressId.Value) is not Address shippingAddress)\r\n                    throw new NopException($\"Shipping is required, but address is not available. Order ID = {order.Id}\");\r\n\r\n                if (!string.IsNullOrEmpty(shippingAddress.Company))\r\n                    addressResult.Company = shippingAddress.Company;\r\n\r\n                addressResult.Name = $\"{shippingAddress.FirstName} {shippingAddress.LastName}\";\r\n\r\n                if (_addressSettings.PhoneEnabled)\r\n                    addressResult.Phone = shippingAddress.PhoneNumber;\r\n\r\n                if (_addressSettings.FaxEnabled && !string.IsNullOrEmpty(shippingAddress.FaxNumber))\r\n                    addressResult.Fax = shippingAddress.FaxNumber;\r\n\r\n                if (_addressSettings.StreetAddressEnabled)\r\n                    addressResult.Address = shippingAddress.Address1;\r\n\r\n                if (_addressSettings.StreetAddress2Enabled && !string.IsNullOrEmpty(shippingAddress.Address2))\r\n                    addressResult.Address2 = shippingAddress.Address2;\r\n\r","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Common/PdfService.cs#L247-L283","documentation":"Thrown by GetShippingAddressAsync (used during PDF invoice/order print generation) when an order requires shipping (ShippingStatus != ShippingNotRequired), is not a pickup-in-store order, yet has no ShippingAddressId or the address lookup returns null. It indicates an inconsistent order record: the system believes the order must ship but no destination address exists.","triggerScenarios":"Generating a PDF invoice/order print for an order whose ShippingAddressId is null, or whose referenced address was deleted from the Address table. Occurs inside the PDF rendering pipeline when the order's shipping status is NotYetShipped/PartiallyShipped/Shipped but the address row is gone.","commonSituations":"Data corruption or manual DB edits that removed address rows; a migration bug that dropped addresses; an order created through a custom checkout flow that never persisted the shipping address while marking shipping required.","solutions":["Inspect the offending order's ShippingAddressId and ShippingStatus columns; if the address was deleted, restore or reassign a valid address row.","If the order genuinely needs no shipping, correct its ShippingStatus to ShippingNotRequired so the PDF path skips the address lookup.","Guard the PDF-generation caller: skip or render a placeholder when order.ShippingAddressId is null for a shipping-required order, rather than letting the exception surface to the print job.","Audit the custom checkout/integration that created the order to ensure it always persists the shipping address when shipping is required."],"exampleFix":"// before\nvar pdf = await _pdfService.PrintOrderToPdfAsync(order, languageId);\n\n// after\nif (order.ShippingStatus != ShippingStatus.ShippingNotRequired\n    && !order.PickupInStore\n    && order.ShippingAddressId is null)\n{\n    _logger.LogWarning(\"Order {Id} marked shipping-required but has no address; skipping PDF\", order.Id);\n    return;\n}\nvar pdf = await _pdfService.PrintOrderToPdfAsync(order, languageId);","handlingStrategy":"validation","validationCode":"if (order.ShippingStatus != ShippingStatus.ShippingNotRequired\n    && !order.PickupInStore\n    && (order.ShippingAddressId is null\n        || await _addressService.GetAddressByIdAsync(order.ShippingAddressId.Value) is null))\n{\n    _logger.LogWarning(\"Order {Id} shipping-required but address missing\", order.Id);\n    return; // skip PDF\n}","typeGuard":null,"tryCatchPattern":"try { await _pdfService.PrintOrderToPdfAsync(order, langId); }\ncatch (NopException ex) when (ex.Message.Contains(\"Shipping is required\"))\n{ _logger.LogError(ex, \"Cannot print order {Id}: missing shipping address\", order.Id); }","preventionTips":["Audit checkout flows to always persist a shipping address when shipping is required.","Add a data-integrity check that flags orders with ShippingStatus != NotRequired and null ShippingAddressId.","Never delete Address rows referenced by orders; soft-delete instead."],"tags":["pdf","shipping","order","address","data-integrity"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}