nopSolutions/nopCommerce · warning · ArgumentException

No affiliate found with the specified id

Error message

No affiliate found with the specified id

What it means

Thrown by AffiliateController.AffiliatedOrderListGrid (permission: AFFILIATES_VIEW). The grid loads the parent affiliate by searchModel.AffliateId (note the typo 'AffliateId' in the model) and throws ArgumentException if not found. The affiliate was deleted or the id is invalid.

Source

Thrown at src/Presentation/Nop.Web/Areas/Admin/Controllers/AffiliateController.cs:223

        await _affiliateService.DeleteAffiliateAsync(affiliate);

        //activity log
        await _customerActivityService.InsertActivityAsync("DeleteAffiliate",
            string.Format(await _localizationService.GetResourceAsync("ActivityLog.DeleteAffiliate"), affiliate.Id), affiliate);

        _notificationService.SuccessNotification(await _localizationService.GetResourceAsync("Admin.Affiliates.Deleted"));

        return RedirectToAction("List");
    }

    [HttpPost]
    [CheckPermission(StandardPermission.Promotions.AFFILIATES_VIEW)]
    public virtual async Task<IActionResult> AffiliatedOrderListGrid(AffiliatedOrderSearchModel searchModel)
    {
        //try to get an affiliate with the specified id
        var affiliate = await _affiliateService.GetAffiliateByIdAsync(searchModel.AffliateId)
                        ?? throw new ArgumentException("No affiliate found with the specified id");

        //prepare model
        var model = await _affiliateModelFactory.PrepareAffiliatedOrderListModelAsync(searchModel, affiliate);

        return Json(model);
    }

    [HttpPost]
    [CheckPermission(StandardPermission.Promotions.AFFILIATES_VIEW)]
    public virtual async Task<IActionResult> AffiliatedCustomerList(AffiliatedCustomerSearchModel searchModel)
    {
        //try to get an affiliate with the specified id
        var affiliate = await _affiliateService.GetAffiliateByIdAsync(searchModel.AffliateId)
                        ?? throw new ArgumentException("No affiliate found with the specified id");

        //prepare model
        var model = await _affiliateModelFactory.PrepareAffiliatedCustomerListModelAsync(searchModel, affiliate);

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Navigate back to the affiliate list and reopen an existing affiliate's order grid.
  2. Return an empty grid instead of throwing when the parent affiliate is missing.
  3. Confirm the request body actually carries a valid AffliateId field (mind the spelling).

Example fix

// before
var affiliate = await _affiliateService.GetAffiliateByIdAsync(searchModel.AffliateId)
                ?? throw new ArgumentException("No affiliate found with the specified id");

// after
var affiliate = await _affiliateService.GetAffiliateByIdAsync(searchModel.AffliateId);
if (affiliate == null)
    return Json(new AffiliatedOrderListModel());
Defensive patterns

Strategy: validation

Validate before calling

// Validate affiliate exists before building the affiliated-orders grid.
var affiliate = await _affiliateService.GetAffiliateByIdAsync(searchModel.AffliateId);
if (affiliate == null) return Json(new AffiliatedOrderListModel());

Type guard

static bool AffiliateExists(Affiliate a) => a is not null;

Try / catch

try { /* AffiliatedOrderListGrid body */ }
catch (ArgumentException ex) when (ex.Message.Contains("affiliate"))
{
    return Json(new AffiliatedOrderListModel());
}

Prevention

When it happens

Trigger: POST AffiliatedOrderListGrid with an AffliateId that GetAffiliateByIdAsync cannot resolve — the affiliate record was removed while its orders tab was open, or the grid holds a stale id.

Common situations: Affiliate deleted in another tab while its affiliated-orders grid is still mounted; copy-paste of an affiliate id after a merge/purge; stale client-side state.

Related errors


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