dotnet/wpf · error · System.ArgumentException

SR.NothingToSign

Error message

SR.NothingToSign

What it means

GenerateManifest throws NothingToSign when, after generating references for all specified parts and relationship selectors, no parts were given and zero relationships matched — the resulting <Manifest> would be empty, which XML-DSig forbids. The library refuses to create a signature over nothing.

Solutions

  1. Pass a non-empty parts list to Sign, or ensure relationshipSelectors match at least one relationship
  2. Verify relationship type strings in selectors exactly match those in the package
  3. Check the package actually contains the content you intend to sign before signing
  4. If the package is legitimately empty, don't sign it — guard the call and skip

Example fix

// before
manager.Sign(null, new RelationshipSelector[0]); // nothing matches
// after
var parts = new List<Uri> { PackUriHelper.CreatePartUri(new Uri("/doc.xml", UriKind.Relative)) };
manager.Sign(parts, null);
Defensive patterns

Strategy: validation

Validate before calling

bool HasSomethingToSign(PackageDigitalSignatureManager mgr,
    IEnumerable<Uri> parts, IEnumerable<RelationshipSelector> selectors)
{
    if (parts != null && parts.Any()) return true;
    if (selectors != null)
    {
        var pkgPart = /* iterate package parts */ true;
        // ensure at least one relationship matches any selector
        return selectors.Any(s => /* package relationships match s */ true);
    }
    return false;
}

Try / catch

try { manager.Sign(parts, relationshipSelectors); }
catch (ArgumentException ex) when (ex.ParamName == null || ex.Message.Contains("sign")) { /* skip signing empty package */ }

Prevention

When it happens

Trigger: Calling PackageDigitalSignatureManager.Sign (leading to GenerateManifest) with parts == null and relationshipSelectors that match no relationships in the package (e.g. empty selector list or selectors whose relationship types do not exist).

Common situations: Signing a package before any parts/relationships were added; typos in relationship type strings so selectors match nothing; passing null parts while relying on RelationshipSelector filters that evaluate to zero hits.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/MS/Internal/IO/Packaging/XmlSignatureManifest.cs:509

            {
                // loop and write - may still be empty
                foreach (Uri partUri in parts)
                {
                    // generate a reference tag
                    manifest.AppendChild(GeneratePartSigningReference(manager, xDoc, hashAlgorithm, partUri));
                }
            }

            // any relationship references?
            int relationshipCount = 0;
            if (relationshipSelectors != null)
            {
                relationshipCount = GenerateRelationshipSigningReferences(manager, xDoc, hashAlgorithm, relationshipSelectors, manifest);
            }

            // did we sign anything? Manifest can NOT be empty
            if (parts == null && relationshipCount == 0)
                throw new ArgumentException(SR.NothingToSign);

            return manifest;
        }

        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------
        /// <summary>
        /// GenerateRelationshipSigningReferences
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="xDoc"></param>
        /// <param name="hashAlgorithm"></param>
        /// <param name="relationshipSelectors"></param>
        /// <param name="manifest"></param>
        /// <returns>number of references to be signed</returns>

View on GitHub (pinned to 81131a70a4)