dotnet/wpf · error · ArgumentException

Specified part to sign does not exist.

Error message

Specified part to sign does not exist.

What it means

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.

Solutions

  1. Verify each part before signing: if (!package.PartExists(partUri)) create it or fix the URI.
  2. Build part URIs with PackUriHelper.CreatePartUri to guarantee correct escaping/format.
  3. Check spelling and casing of the part path — OPC part comparison is case-sensitive.

Example fix

// before
Uri part = new Uri("/doc.xml", UriKind.Relative);
mgr.Sign(cert, new Uri[] { part }); // ArgumentException: part missing
// after
Uri part = PackUriHelper.CreatePartUri(new Uri("/documents/doc.xml", UriKind.Relative));
if (!pkg.PartExists(part)) pkg.CreatePart(part, "application/xml");
mgr.Sign(cert, new Uri[] { part });
Defensive patterns

Strategy: validation

Validate before calling

foreach (var part in parts)
    if (!package.PartExists(part))
        throw new InvalidOperationException($"Part {part} does not exist; cannot sign.");

Try / catch

try { mgr.Sign(cert, parts); }
catch (ArgumentException ex) when (ex.ParamName == "parts") { /* fix part URIs / create missing parts */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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).

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/72e33bd36d85ad0e. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs:922

        /// Verify Parts Exist before signing
        /// </summary>
        /// <param name="parts"></param>
        /// <remarks>This call must be done after the signature Origin has been created to allow for 
        /// callers to sign an Origin (or it's relationship part) for the first signature in the package.</remarks>
        private void VerifyPartsExist(IEnumerable<Uri> parts)
        {
            // check for missing parts
            if (parts != null)
            {
                foreach (Uri partUri in parts)
                {
                    if (!_container.PartExists(partUri))
                    {
                        // delete origin part if it was created and this is the first signature
                        if (_signatures.Count == 0)
                            DeleteOriginPart();

                        throw new ArgumentException(SR.PartToSignMissing, nameof(parts));
                    }
                }
            }
}

        /// <summary>
        /// Verifies arguments to Sign() method - sub-function to reduce complexity in Sign() logic
        /// </summary>
        /// <param name="parts"></param>
        /// <param name="certificate"></param>
        /// <param name="relationshipSelectors"></param>
        /// <param name="signatureId"></param>
        /// <param name="signatureObjects"></param>
        /// <param name="objectReferences"></param>
        private void VerifySignArguments(IEnumerable<Uri> parts,
            X509Certificate certificate,
            IEnumerable<PackageRelationshipSelector> relationshipSelectors,
            String signatureId,

View on GitHub (pinned to 81131a70a4)