{"record":{"id":"72e33bd36d85ad0e","repo":"dotnet/wpf","slug":"specified-part-to-sign-does-not-exist","errorCode":null,"errorMessage":"Specified part to sign does not exist.","messagePattern":"Specified part to sign does not exist\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs","lineNumber":922,"sourceCode":"        /// Verify Parts Exist before signing\n        /// </summary>\n        /// <param name=\"parts\"></param>\n        /// <remarks>This call must be done after the signature Origin has been created to allow for \n        /// callers to sign an Origin (or it's relationship part) for the first signature in the package.</remarks>\n        private void VerifyPartsExist(IEnumerable<Uri> parts)\n        {\n            // check for missing parts\n            if (parts != null)\n            {\n                foreach (Uri partUri in parts)\n                {\n                    if (!_container.PartExists(partUri))\n                    {\n                        // delete origin part if it was created and this is the first signature\n                        if (_signatures.Count == 0)\n                            DeleteOriginPart();\n\n                        throw new ArgumentException(SR.PartToSignMissing, nameof(parts));\n                    }\n                }\n            }\n}\n\n        /// <summary>\n        /// Verifies arguments to Sign() method - sub-function to reduce complexity in Sign() logic\n        /// </summary>\n        /// <param name=\"parts\"></param>\n        /// <param name=\"certificate\"></param>\n        /// <param name=\"relationshipSelectors\"></param>\n        /// <param name=\"signatureId\"></param>\n        /// <param name=\"signatureObjects\"></param>\n        /// <param name=\"objectReferences\"></param>\n        private void VerifySignArguments(IEnumerable<Uri> parts,\n            X509Certificate certificate,\n            IEnumerable<PackageRelationshipSelector> relationshipSelectors,\n            String signatureId,","sourceCodeStart":904,"sourceCodeEnd":940,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs#L904-L940","documentation":"Sign() validates that every part URI passed in the parts collection actually exists in the package via _container.PartExists; if any part is missing it throws ArgumentException (SR.PartToSignMissing) naming the parts parameter. If this was the first signature it also deletes the just-created origin part to leave the package unchanged.","triggerScenarios":"Calling Sign(certificate, parts, ...) with a part Uri that does not exist in the package — wrong part path, part never created, or case/escape mismatch in the PackUriHelper part name.","commonSituations":"Hard-coding a part name like '/document.xml' when the actual part is '/word/document.xml'; signing parts of a package rebuilt dynamically where the part creation was skipped; URI casing mismatches (OPC part names are case-sensitive).","solutions":["Verify each part before signing: if (!package.PartExists(partUri)) create it or fix the URI.","Build part URIs with PackUriHelper.CreatePartUri to guarantee correct escaping/format.","Check spelling and casing of the part path — OPC part comparison is case-sensitive."],"exampleFix":"// before\nUri part = new Uri(\"/doc.xml\", UriKind.Relative);\nmgr.Sign(cert, new Uri[] { part }); // ArgumentException: part missing\n// after\nUri part = PackUriHelper.CreatePartUri(new Uri(\"/documents/doc.xml\", UriKind.Relative));\nif (!pkg.PartExists(part)) pkg.CreatePart(part, \"application/xml\");\nmgr.Sign(cert, new Uri[] { part });","handlingStrategy":"validation","validationCode":"foreach (var part in parts)\n    if (!package.PartExists(part))\n        throw new InvalidOperationException($\"Part {part} does not exist; cannot sign.\");","typeGuard":null,"tryCatchPattern":"try { mgr.Sign(cert, parts); }\ncatch (ArgumentException ex) when (ex.ParamName == \"parts\") { /* fix part URIs / create missing parts */ }","preventionTips":["Create part URIs with PackUriHelper.CreatePartUri, not raw Uri constructors.","Verify PartExists for each part before signing.","OPC part names are case-sensitive — check casing carefully."],"tags":["wpf","packaging","argument","part-not-found","digital-signature"],"backgroundTag":"resource-not-found","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"}