dotnet/wpf · error · InvalidDataException

Document has more than one Signature Definition…

Error message

Document has more than one Signature Definition relationship.

What it means

GetSignatureDefinitionPart enforces the XPS rule that a document part may have at most one Signature Definition relationship. While enumerating relationships of type SignatureDefinitionRelationshipName, a second one triggers InvalidDataException SR.ReachPackaging_MoreThanOneSigDefParts — the package is structurally invalid.

Solutions

  1. Inspect the package with a ZIP/tool viewer and remove the duplicate Signature Definition relationships/parts.
  2. Fix the generating code to add only one signature definition relationship per document part.
  3. Regenerate or re-save the package with a compliant writer (e.g. re-export through WPF XPS APIs) to normalize relationships.
  4. If authoring signatures, reuse the existing SigDef part instead of creating a new relationship each time.

Example fix

// before
foreach (var sig in signatures)
    documentPart.CreateRelationship(sig.Uri, TargetMode.Internal, XpsS0Markup.SignatureDefinitionRelationshipName);
// after
bool has = documentPart.GetRelationshipsByType(XpsS0Markup.SignatureDefinitionRelationshipName).Any();
if (!has)
    documentPart.CreateRelationship(sig.Uri, TargetMode.Internal, XpsS0Markup.SignatureDefinitionRelationshipName);
Defensive patterns

Strategy: validation

Validate before calling

int sigDefCount = documentPart.GetRelationshipsByType(XpsS0Markup.SignatureDefinitionRelationshipName).Count();
if (sigDefCount > 1) throw new InvalidDataException("Package contains more than one Signature Definition relationship");

Type guard

bool HasSingleSigDef(PackagePart p) => p.GetRelationshipsByType(XpsS0Markup.SignatureDefinitionRelationshipName).Count() <= 1;

Try / catch

try { return xpsManager.GetSignatureDefinitionPart(documentUri); }
catch (InvalidDataException ex) when (ex.Message.Contains("Signature Definition")) { /* treat package as non-conformant; repair or reject */ }

Prevention

When it happens

Trigger: Reading a package whose document part carries two or more relationships of type XpsS0Markup.SignatureDefinitionRelationshipName, typically because a tool wrote duplicate signature definition parts.

Common situations: Packages produced by non-Microsoft or buggy XPS generators that add a signature definition per signature instead of one per document; round-tripping a package through custom code that appends relationships without checking existing ones.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs:591

        {
            PackagePart documentPart = _metroPackage.GetPart( documentUri );
            PackagePart sigDefPart = null;

            if( documentPart == null )
            {
              throw new InvalidDataException(SR.ReachPackaging_InvalidDocUri);
            }

            ContentType SignitureDefType =
                XpsS0Markup.SignatureDefintionType;
            PackageRelationship SigDefRel = null;

            foreach (PackageRelationship rel in
                     documentPart.GetRelationshipsByType(XpsS0Markup.SignatureDefinitionRelationshipName))
            {
                if (SigDefRel != null)
                {
                    throw new InvalidDataException(SR.ReachPackaging_MoreThanOneSigDefParts);
                }

                SigDefRel = rel;
            }
            if (SigDefRel != null)
            {
                sigDefPart = _metroPackage.GetPart(PackUriHelper.ResolvePartUri(SigDefRel.SourceUri, SigDefRel.TargetUri));
            }
            return sigDefPart;
        }

        public
        PackagePart
        GetDocumentPropertiesPart()
        {
            PackageRelationship propertiesPartRelationship =
                   GetDocumentPropertiesReationship();

View on GitHub (pinned to 81131a70a4)