{"record":{"id":"02c3162246d734ab","repo":"dotnet/wpf","slug":"sr-jumpitemsrejectedeventargs-countmismatch","errorCode":null,"errorMessage":"SR.JumpItemsRejectedEventArgs_CountMismatch","messagePattern":"SR\\.JumpItemsRejectedEventArgs_CountMismatch","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs","lineNumber":62,"sourceCode":"    }\n\n    /// <summary>\n    /// EventArgs for JumpList.JumpItemsRejected event.\n    /// </summary>\n    public sealed class JumpItemsRejectedEventArgs : EventArgs\n    {\n        public JumpItemsRejectedEventArgs()\n            : this(null, null)\n        { }\n\n        public JumpItemsRejectedEventArgs(IList<JumpItem> rejectedItems, IList<JumpItemRejectionReason> reasons)\n        {\n            // If one of the collections is null then the other has to be, too.\n            if ((rejectedItems == null && reasons != null)\n                || (reasons == null && rejectedItems != null)\n                || (rejectedItems != null && reasons != null && rejectedItems.Count != reasons.Count))\n            {\n                throw new ArgumentException(SR.JumpItemsRejectedEventArgs_CountMismatch);\n            }\n\n            // We don't want the contents of the list getting modified in the event handler,\n            // so use a read-only copy\n            if (rejectedItems != null)\n            {\n                RejectedItems = new List<JumpItem>(rejectedItems).AsReadOnly();\n                RejectionReasons = new List<JumpItemRejectionReason>(reasons).AsReadOnly();\n            }\n            else\n            {\n                RejectedItems = new List<JumpItem>().AsReadOnly();\n                RejectionReasons = new List<JumpItemRejectionReason>().AsReadOnly();\n            }\n        }\n\n        public IList<JumpItem> RejectedItems { get; private set; }\n        public IList<JumpItemRejectionReason> RejectionReasons { get; private set; }","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Shell/JumpList.cs#L44-L80","documentation":"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.","triggerScenarios":"`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).","commonSituations":"Custom JumpList.RejectItems handling code that aggregates reasons but drops entries for items filtered out earlier; hand-rolling event args when forwarding rejection data.","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."],"exampleFix":"// before\nvar args = new JumpItemsRejectedEventArgs(rejected, reasons.Take(1).ToList()); // count mismatch\n// after\nif (rejected.Count == reasons.Count)\n    var args = new JumpItemsRejectedEventArgs(rejected, reasons);","handlingStrategy":"validation","validationCode":"bool IsValidPair(System.Collections.Generic.IList<JumpItem> items, System.Collections.Generic.IList<JumpItemRejectionReason> reasons) =>\n    (items == null && reasons == null) || (items != null && reasons != null && items.Count == reasons.Count);","typeGuard":null,"tryCatchPattern":"try { var args = new JumpItemsRejectedEventArgs(rejected, reasons); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"CountMismatch\")) { /* resync lists */ }","preventionTips":["Build rejectedItems and reasons in the same loop so counts stay equal","Pass null for both collections together when there are no rejections"],"tags":["wpf","jumplist","argument-count-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}