dotnet/wpf · error · ArgumentException
SR.JumpItemsRejectedEventArgs_CountMismatch
Error message
SR.JumpItemsRejectedEventArgs_CountMismatch
What it means
The JumpItemsRejectedEventArgs constructor requires the rejectedItems and reasons collections to be null together or non-null with equal counts, since each rejected jump item needs exactly one rejection reason. Any mismatch throws ArgumentException with JumpItemsRejectedEventArgs_CountMismatch.
Solutions
- Ensure reasons.Count equals rejectedItems.Count, one reason per rejected item, before constructing the args.
- Pass null for both parameters together if there are no rejections.
- Build the lists in the same loop so index counts stay synchronized.
Example fix
// before
var args = new JumpItemsRejectedEventArgs(rejected, reasons.Take(1).ToList()); // count mismatch
// after
if (rejected.Count == reasons.Count)
var args = new JumpItemsRejectedEventArgs(rejected, reasons); Defensive patterns
Strategy: validation
Validate before calling
bool IsValidPair(System.Collections.Generic.IList<JumpItem> items, System.Collections.Generic.IList<JumpItemRejectionReason> reasons) =>
(items == null && reasons == null) || (items != null && reasons != null && items.Count == reasons.Count); Try / catch
try { var args = new JumpItemsRejectedEventArgs(rejected, reasons); }
catch (ArgumentException ex) when (ex.Message.Contains("CountMismatch")) { /* resync lists */ } Prevention
- Build rejectedItems and reasons in the same loop so counts stay equal
- Pass null for both collections together when there are no rejections
When it happens
Trigger: `new JumpItemsRejectedEventArgs(items, reasons)` where one is null and the other is not, or where items.Count != reasons.Count (e.g. one reason omitted, or an empty reasons list with non-empty items).
Common situations: Custom JumpList.RejectItems handling code that aggregates reasons but drops entries for items filtered out earlier; hand-rolling event args when forwarding rejection data.
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
- SR.JumpList_CantApplyUntilEndInit
- SR.JumpList_CantCallUnbalancedEndInit
- SR.JumpList_CantNestBeginInitCalls
- " }} " element found. Expected fixed page element ( }} ).
- ' ' can only host a ' ' or a ' '. ' ' is an invalid…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/02c3162246d734ab.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs:62
}
/// <summary>
/// EventArgs for JumpList.JumpItemsRejected event.
/// </summary>
public sealed class JumpItemsRejectedEventArgs : EventArgs
{
public JumpItemsRejectedEventArgs()
: this(null, null)
{ }
public JumpItemsRejectedEventArgs(IList<JumpItem> rejectedItems, IList<JumpItemRejectionReason> reasons)
{
// If one of the collections is null then the other has to be, too.
if ((rejectedItems == null && reasons != null)
|| (reasons == null && rejectedItems != null)
|| (rejectedItems != null && reasons != null && rejectedItems.Count != reasons.Count))
{
throw new ArgumentException(SR.JumpItemsRejectedEventArgs_CountMismatch);
}
// We don't want the contents of the list getting modified in the event handler,
// so use a read-only copy
if (rejectedItems != null)
{
RejectedItems = new List<JumpItem>(rejectedItems).AsReadOnly();
RejectionReasons = new List<JumpItemRejectionReason>(reasons).AsReadOnly();
}
else
{
RejectedItems = new List<JumpItem>().AsReadOnly();
RejectionReasons = new List<JumpItemRejectionReason>().AsReadOnly();
}
}
public IList<JumpItem> RejectedItems { get; private set; }
public IList<JumpItemRejectionReason> RejectionReasons { get; private set; }View on GitHub (pinned to 81131a70a4)