{"record":{"id":"c1a574f7883fa1b7","repo":"dotnet/wpf","slug":"must-specify-an-item-to-sign","errorCode":null,"errorMessage":"Must specify an item to sign.","messagePattern":"Must specify an item to sign\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs","lineNumber":396,"sourceCode":"        /// Sign - certificate provided by caller\n        /// </summary>\n        /// <param name=\"parts\">list of parts to sign - may be empty or null</param>\n        /// <param name=\"certificate\">signer's certificate</param>\n        /// <param name=\"relationshipSelectors\">relationshipSelectors that hold information about \n        /// the relationships to be signed - may be empty or null</param>\n        /// <param name=\"signatureId\">id for the new Signature - may be empty or null</param>  \n        /// <remarks>one of parts or relationships must be non-null and contain at least a single entry</remarks>\n        public PackageDigitalSignature Sign(\n            IEnumerable<Uri> parts,\n            X509Certificate certificate,\n            IEnumerable<PackageRelationshipSelector> relationshipSelectors,\n            String signatureId)\n        {\n            // Cannot both be null - need to check here because the similar check in the super-overload cannot\n            // distinguish to this level.\n            if (parts == null && relationshipSelectors == null)\n            {\n                throw new ArgumentException(SR.NothingToSign);\n            }\n\n            return Sign(parts, certificate, relationshipSelectors, signatureId, null, null);\n        }\n\n        /// <summary>\n        /// Sign - caller specifies custom \"Object\" and/or SignedInfo \"Reference\" tags\n        /// </summary>\n        /// <param name=\"parts\">list of parts to sign - may be empty or null</param>\n        /// <param name=\"certificate\">signer's certificate</param>\n        /// <param name=\"relationshipSelectors\">relationshipSelectors that hold information about \n        /// the relationships to be signed - may be empty or null</param>\n        /// <param name=\"signatureId\">id for the new Signature - may be empty or null</param>  \n        /// <param name=\"objectReferences\">references to custom object tags.  The DigestMethod on each\n        /// Reference will be ignored.  The signature will use the globally defined HashAlgorithm\n        /// obtained from the current value of the HashAlgorithm property.</param>\n        /// <param name=\"signatureObjects\">objects (signed or not)</param>\n        /// <exception cref=\"InvalidOperationException\">Thrown if any TransformMapping","sourceCodeStart":378,"sourceCodeEnd":414,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs#L378-L414","documentation":"The two-parameter Sign overload (parts and relationshipSelectors) requires at least one of its inputs to be non-null; both being null means there is nothing to include in the signature, so it throws ArgumentException (SR.NothingToSign).","triggerScenarios":"Calling Sign(null, certificate, null, signatureId) — i.e. both the parts collection and the relationshipSelectors collection are null.","commonSituations":"Passing variables that were initialized to null on a code path where content selection failed; conditional logic that skipped populating the parts list; refactoring that removed the actual items but left the Sign call.","solutions":["Pass at least one PackagePart in the parts list or at least one PackageRelationshipSelector in relationshipSelectors","Guard with a null check on both arguments before calling Sign","If you intend to sign the entire package, enumerate the package parts and pass them","Catch ArgumentException and surface a clear 'nothing selected to sign' message to the user"],"exampleFix":"// before\nmanager.Sign(parts, cert, selectors, null); // both parts and selectors may be null\n// after\nbool hasParts = parts != null && parts.Any();\nbool hasSelectors = selectors != null && selectors.Any();\nif (hasParts || hasSelectors)\n    manager.Sign(parts, cert, selectors, null);","handlingStrategy":"validation","validationCode":"if ((parts == null || !parts.Any()) && (selectors == null || !selectors.Any()))\n    throw new ArgumentException(\"Specify at least one part or relationship selector to sign.\");","typeGuard":null,"tryCatchPattern":"try { manager.Sign(parts, cert, selectors, null); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"sign\")) { log.Error(\"Nothing to sign\", ex); }","preventionTips":["Check that the parts collection was actually populated before signing","Fail early in selection logic so Sign is never called with empty input","Prefer Sign(IEnumerable<Uri>) with explicit part URIs when selection is complex"],"tags":["wpf","packaging","argumentexception","missing-argument"],"backgroundTag":"missing-required-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}