{"record":{"id":"2ac66db4cdd43c01","repo":"HandyOrg/HandyControl","slug":"the-counts-of-rejected-items-doesn-t-match-the-count-of","errorCode":null,"errorMessage":"The counts of rejected items doesn't match the count of reasons.","messagePattern":"The counts of rejected items doesn't match the count of reasons\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Shared/Microsoft.Windows.Shell/JumpItemsRejectedEventArgs.cs","lineNumber":16,"sourceCode":"﻿using System;\nusing System.Collections.Generic;\n\nnamespace Microsoft.Windows.Shell;\n\npublic sealed class JumpItemsRejectedEventArgs : EventArgs\n{\n    public JumpItemsRejectedEventArgs() : this(null, null)\n    {\n    }\n\n    public JumpItemsRejectedEventArgs(IList<JumpItem> rejectedItems, IList<JumpItemRejectionReason> reasons)\n    {\n        if ((rejectedItems == null && reasons != null) || (reasons == null && rejectedItems != null) || (rejectedItems != null && reasons != null && rejectedItems.Count != reasons.Count))\n        {\n            throw new ArgumentException(\"The counts of rejected items doesn't match the count of reasons.\");\n        }\n        if (rejectedItems != null)\n        {\n            this.RejectedItems = new List<JumpItem>(rejectedItems).AsReadOnly();\n            this.RejectionReasons = new List<JumpItemRejectionReason>(reasons).AsReadOnly();\n            return;\n        }\n        this.RejectedItems = new List<JumpItem>().AsReadOnly();\n        this.RejectionReasons = new List<JumpItemRejectionReason>().AsReadOnly();\n    }\n\n    public IList<JumpItem> RejectedItems { get; private set; }\n\n    public IList<JumpItemRejectionReason> RejectionReasons { get; private set; }\n}\n","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/Microsoft.Windows.Shell/JumpItemsRejectedEventArgs.cs#L1-L32","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar args = new JumpItemsRejectedEventArgs(rejectedItems, reasons); // counts 3 vs 2 -> ArgumentException\n\n// after\nvar pairs = items.Zip(reasons, (i, r) => new { i, r }).Where(p => ShouldReject(p.i)).ToList();\nvar args = new JumpItemsRejectedEventArgs(\n    pairs.Select(p => p.i).ToList(),\n    pairs.Select(p => p.r).ToList()); // always equal counts","handlingStrategy":"validation","validationCode":"if (rejectedItems == null != (reasons == null) || (rejectedItems != null && rejectedItems.Count != reasons.Count))\n    throw new ArgumentException(\"rejectedItems and reasons must be both null or same-length lists.\");","typeGuard":null,"tryCatchPattern":"try { args = new JumpItemsRejectedEventArgs(items, reasons); }\ncatch (ArgumentException ex) { Log.Error(ex.Message); args = null; }","preventionTips":["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."],"tags":["argument","jump-list","shell","wpf"],"backgroundTag":"invalid-argument-value","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}