{"record":{"id":"aeda880a8d3f0e1f","repo":"nopSolutions/nopCommerce","slug":"order-cannot-be-loaded","errorCode":null,"errorMessage":"Order cannot be loaded","messagePattern":"Order cannot be loaded","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"src/Libraries/Nop.Services/Orders/OrderProcessingService.cs","lineNumber":2238,"sourceCode":"            return false;\r\n\r\n        if (orderCustomer == null || (!await _customerService.IsAdminAsync(customer) && orderCustomer.Id != customer.Id))\r\n            return false;\r\n\r\n        return true;\r\n    }\r\n\r\n    /// <summary>\r\n    /// Send a shipment\r\n    /// </summary>\r\n    /// <param name=\"shipment\">Shipment</param>\r\n    /// <param name=\"notifyCustomer\">True to notify customer</param>\r\n    /// <returns>A task that represents the asynchronous operation</returns>\r\n    public virtual async Task ShipAsync(Shipment shipment, bool notifyCustomer)\r\n    {\r\n        ArgumentNullException.ThrowIfNull(shipment);\r\n\r\n        var order = await _orderService.GetOrderByIdAsync(shipment.OrderId) ?? throw new Exception(\"Order cannot be loaded\");\r\n\r\n        if (order.PickupInStore)\r\n            throw new Exception(\"This shipment is can't be shipped. The order has been placed with 'pickup in store' shipping option.\");\r\n\r\n        if (shipment.ShippedDateUtc.HasValue)\r\n            throw new Exception(\"This shipment is already shipped\");\r\n\r\n        shipment.ShippedDateUtc = DateTime.UtcNow;\r\n        await _shipmentService.UpdateShipmentAsync(shipment);\r\n\r\n        //process products with \"Multiple warehouse\" support enabled\r\n        await BookReservedInventoryAsync(shipment, string.Format(await _localizationService.GetResourceAsync(\"Admin.StockQuantityHistory.Messages.Ship\"), shipment.OrderId));\r\n\r\n        //check whether we have more items to ship\r\n        if (await _orderService.HasItemsToAddToShipmentAsync(order) || await _orderService.HasItemsToShipAsync(order))\r\n            order.ShippingStatusId = (int)ShippingStatus.PartiallyShipped;\r\n        else\r\n            order.ShippingStatusId = (int)ShippingStatus.Shipped;\r","sourceCodeStart":2220,"sourceCodeEnd":2256,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Orders/OrderProcessingService.cs#L2220-L2256","documentation":"Thrown by OrderProcessingService.ShipAsync when _orderService.GetOrderByIdAsync(shipment.OrderId) returns null. A shipment exists referencing an order id that no longer resolves - typically an orphaned shipment after the parent order was hard-deleted. Note this uses plain System.Exception, not NopException.","triggerScenarios":"Calling ShipAsync on a shipment whose OrderId points to a deleted/non-existent order; data import that created shipments without their orders; partial DB restore.","commonSituations":"Order cleanup scripts that delete orders but leave shipments; faulty migration; manual DB surgery; testing with synthetic shipment fixtures.","solutions":["Restore the parent order from backup, or delete the orphaned shipment if the order is genuinely gone.","Fix order-deletion routines to cascade-remove shipments.","Validate shipment.OrderId resolves before invoking ShipAsync."],"exampleFix":"// before\nawait _orderProcessingService.ShipAsync(shipment, true);\n\n// after\nvar order = await _orderService.GetOrderByIdAsync(shipment.OrderId);\nif (order is null)\n    return BadRequest($\"Order {shipment.OrderId} for shipment {shipment.Id} not found.\");\nawait _orderProcessingService.ShipAsync(shipment, true);","handlingStrategy":"validation","validationCode":"var order = await _orderService.GetOrderByIdAsync(shipment.OrderId);\nif (order is null)\n    return BadRequest($\"Shipment {shipment.Id} references deleted order {shipment.OrderId}.\");\n\nawait _orderProcessingService.ShipAsync(shipment, notifyCustomer);","typeGuard":"async Task<bool> ShipmentOrderExistsAsync(Shipment shipment)\n    => await _orderService.GetOrderByIdAsync(shipment.OrderId) is not null;","tryCatchPattern":"try\n{\n    await _orderProcessingService.ShipAsync(shipment, notifyCustomer);\n}\ncatch (Exception ex) when (ex.Message == \"Order cannot be loaded\")\n{\n    return BadRequest(\"Parent order not found. The shipment may be orphaned.\");\n}","preventionTips":["Resolve the parent order before calling ShipAsync and short-circuit if missing.","Cascade-delete shipments when orders are hard-deleted.","Audit data-import routines so shipments are never created without their orders."],"tags":["shipment","order","data-integrity","orphan-record","nopcommerce"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}