HandyOrg/HandyControl · error · ArgumentException

The counts of rejected items doesn't match the count of…

Error message

The counts of rejected items doesn't match the count of reasons.

What it means

The JumpItemsRejectedEventArgs constructor requires rejectedItems and reasons to be either both null or both non-null lists of equal length — each rejected JumpItem must have exactly one JumpItemRejectionReason. Violating that (one null, or mismatched counts) throws this ArgumentException.

Solutions

  1. Always build the two lists together so indexes stay aligned: every rejected item must have a reason at the same index.
  2. Filter both lists with the same predicate (e.g. a single loop over pairs, not two separate loops).
  3. Pass null for both parameters together, or omit them via the parameterless path — never one null and one non-null.
  4. Validate counts with Debug.Assert(rejectedItems.Count == reasons.Count) during development to catch drift early.

Example fix

// before
var args = new JumpItemsRejectedEventArgs(rejectedItems, reasons); // counts 3 vs 2 -> ArgumentException

// after
var pairs = items.Zip(reasons, (i, r) => new { i, r }).Where(p => ShouldReject(p.i)).ToList();
var args = new JumpItemsRejectedEventArgs(
    pairs.Select(p => p.i).ToList(),
    pairs.Select(p => p.r).ToList()); // always equal counts
Defensive patterns

Strategy: validation

Validate before calling

if (rejectedItems == null != (reasons == null) || (rejectedItems != null && rejectedItems.Count != reasons.Count))
    throw new ArgumentException("rejectedItems and reasons must be both null or same-length lists.");

Try / catch

try { args = new JumpItemsRejectedEventArgs(items, reasons); }
catch (ArgumentException ex) { Log.Error(ex.Message); args = null; }

Prevention

When it happens

Trigger: Raising a JumpItemsRejectedEventArgs directly (custom shell integration or testing) with rejectedItems and reasons lists whose counts differ, or passing only one of the two as null.

Common situations: Unit tests constructing the event args manually; custom JumpList plumbing that filters rejected items but forgets to filter the parallel reasons list; refactorings that added items without adding matching reasons.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14). Data as JSON: /api/errors/2ac66db4cdd43c01. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/Microsoft.Windows.Shell/JumpItemsRejectedEventArgs.cs:16

using System;
using System.Collections.Generic;

namespace Microsoft.Windows.Shell;

public sealed class JumpItemsRejectedEventArgs : EventArgs
{
    public JumpItemsRejectedEventArgs() : this(null, null)
    {
    }

    public JumpItemsRejectedEventArgs(IList<JumpItem> rejectedItems, IList<JumpItemRejectionReason> reasons)
    {
        if ((rejectedItems == null && reasons != null) || (reasons == null && rejectedItems != null) || (rejectedItems != null && reasons != null && rejectedItems.Count != reasons.Count))
        {
            throw new ArgumentException("The counts of rejected items doesn't match the count of reasons.");
        }
        if (rejectedItems != null)
        {
            this.RejectedItems = new List<JumpItem>(rejectedItems).AsReadOnly();
            this.RejectionReasons = new List<JumpItemRejectionReason>(reasons).AsReadOnly();
            return;
        }
        this.RejectedItems = new List<JumpItem>().AsReadOnly();
        this.RejectionReasons = new List<JumpItemRejectionReason>().AsReadOnly();
    }

    public IList<JumpItem> RejectedItems { get; private set; }

    public IList<JumpItemRejectionReason> RejectionReasons { get; private set; }
}

View on GitHub (pinned to 2c0875ebd6)