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
- Always build the two lists together so indexes stay aligned: every rejected item must have a reason at the same index.
- Filter both lists with the same predicate (e.g. a single loop over pairs, not two separate loops).
- Pass null for both parameters together, or omit them via the parameterless path — never one null and one non-null.
- 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
- Build rejectedItems and reasons in the same loop so indexes always align.
- Filter with Zip/pairs rather than filtering two lists independently.
- Debug.Assert(rejectedItems.Count == reasons.Count) in dev builds.
- Treat the two lists as one list of (item, reason) tuples in your own model.
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
- Calls to BeginInit cannot be nested.
- Can't call EndInit without first calling BeginInit.
- CannotConvertType
- InvalidFrame
- owner
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)