nopSolutions/nopCommerce · critical · Exception
Order cannot be loaded
Error message
Order cannot be loaded
What it means
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.
Source
Thrown at src/Libraries/Nop.Services/Orders/OrderProcessingService.cs:2238
return false;
if (orderCustomer == null || (!await _customerService.IsAdminAsync(customer) && orderCustomer.Id != customer.Id))
return false;
return true;
}
/// <summary>
/// Send a shipment
/// </summary>
/// <param name="shipment">Shipment</param>
/// <param name="notifyCustomer">True to notify customer</param>
/// <returns>A task that represents the asynchronous operation</returns>
public virtual async Task ShipAsync(Shipment shipment, bool notifyCustomer)
{
ArgumentNullException.ThrowIfNull(shipment);
var order = await _orderService.GetOrderByIdAsync(shipment.OrderId) ?? throw new Exception("Order cannot be loaded");
if (order.PickupInStore)
throw new Exception("This shipment is can't be shipped. The order has been placed with 'pickup in store' shipping option.");
if (shipment.ShippedDateUtc.HasValue)
throw new Exception("This shipment is already shipped");
shipment.ShippedDateUtc = DateTime.UtcNow;
await _shipmentService.UpdateShipmentAsync(shipment);
//process products with "Multiple warehouse" support enabled
await BookReservedInventoryAsync(shipment, string.Format(await _localizationService.GetResourceAsync("Admin.StockQuantityHistory.Messages.Ship"), shipment.OrderId));
//check whether we have more items to ship
if (await _orderService.HasItemsToAddToShipmentAsync(order) || await _orderService.HasItemsToShipAsync(order))
order.ShippingStatusId = (int)ShippingStatus.PartiallyShipped;
else
order.ShippingStatusId = (int)ShippingStatus.Shipped;
View on GitHub (pinned to 64bdf2ff08)
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.
Example fix
// before
await _orderProcessingService.ShipAsync(shipment, true);
// after
var order = await _orderService.GetOrderByIdAsync(shipment.OrderId);
if (order is null)
return BadRequest($"Order {shipment.OrderId} for shipment {shipment.Id} not found.");
await _orderProcessingService.ShipAsync(shipment, true); Defensive patterns
Strategy: validation
Validate before calling
var order = await _orderService.GetOrderByIdAsync(shipment.OrderId);
if (order is null)
return BadRequest($"Shipment {shipment.Id} references deleted order {shipment.OrderId}.");
await _orderProcessingService.ShipAsync(shipment, notifyCustomer); Type guard
async Task<bool> ShipmentOrderExistsAsync(Shipment shipment)
=> await _orderService.GetOrderByIdAsync(shipment.OrderId) is not null; Try / catch
try
{
await _orderProcessingService.ShipAsync(shipment, notifyCustomer);
}
catch (Exception ex) when (ex.Message == "Order cannot be loaded")
{
return BadRequest("Parent order not found. The shipment may be orphaned.");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Order cleanup scripts that delete orders but leave shipments; faulty migration; manual DB surgery; testing with synthetic shipment fixtures.
Related errors
- Initial order could not be loaded
- Customer could not be loaded
- Enter shipped date
- Enter ready for pickup date
- Enter delivery date
AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13).
Data as JSON: /api/errors/aeda880a8d3f0e1f.
Report an issue: GitHub.