dotnet/wpf · error · FileFormatException

SR.SignatureOriginNotFound

Error message

SR.SignatureOriginNotFound

What it means

While locating the Digital Signature Origin part at construction, the manager resolves each internal signature-origin relationship and throws FileFormatException(SR.SignatureOriginNotFound) when the resolved target part does not exist in the package. The package claims a signature origin via a relationship but the actual origin part is missing.

Solutions

  1. Add back the missing signature origin part at the path the relationship targets
  2. Remove the dangling signature-origin relationship from the root .rels, then re-sign with Sign
  3. Rebuild/re-sign the package from a known-good copy
  4. If signatures are irrelevant to your workflow, catch FileFormatException and proceed without signature support

Example fix

// before: dangling relationship in _rels/.rels
// after: remove the relationship, then
using var pkg = Package.Open(path, FileMode.Open, FileAccess.ReadWrite);
var signer = new PackageDigitalSignatureManager(pkg) { Certificate = cert };
signer.Sign(new Uri("/metadata/sig-origin.xml", UriKind.Relative));
Defensive patterns

Strategy: try-catch

Validate before calling

bool originPartExists = pkg.GetRelationshipsByType(
    "http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin")
    .Where(r => r.TargetMode == TargetMode.Internal)
    .Any(r => pkg.PartExists(PackUriHelper.ResolvePartUri("/", r.TargetUri)));

Try / catch

try { var signer = new PackageDigitalSignatureManager(pkg); }
catch (FileFormatException)
{ /* no usable origin; treat as unsigned or re-sign */ }

Prevention

When it happens

Trigger: Constructing PackageDigitalSignatureManager on a package whose root relationship of type http://schemas.openxmlformats.org/package/2006/relationships/digital-signature/origin points to a part that is absent (deleted or not copied).

Common situations: Signature origin part stripped during repackaging or signing removal done incorrectly; zip tooling that dropped the part; partial file transfer truncation.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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

Appendix: source

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

            // only search once
            if (!_originSearchConducted)
            {
                try
                {
                    Debug.Assert(!_originPartExists, "Logic Error: If OriginPartExists, OriginSearchConducted should be true.");
                    PackageRelationshipCollection containerRelationships = _container.GetRelationshipsByType(_originRelationshipType);
                    foreach (PackageRelationship r in containerRelationships)
                    {
                        // don't resolve if external
                        if (r.TargetMode != TargetMode.Internal)
                            throw new FileFormatException(SR.PackageSignatureCorruption);

                        // resolve target (may be relative)
                        Uri targetUri = PackUriHelper.ResolvePartUri(r.SourceUri, r.TargetUri);

                        // if part does not exist - we throw
                        if (!_container.PartExists(targetUri))
                            throw new FileFormatException(SR.SignatureOriginNotFound);

                        PackagePart p = _container.GetPart(targetUri);

                        // inspect content type - ignore things we don't understand
                        if (p.ValidatedContentType().AreTypeAndSubTypeEqual(_originPartContentType))
                        {
                            // throw if more than one relationship to an origin part that we recognize
                            if (_originPartExists)
                                throw new FileFormatException(SR.MultipleSignatureOrigins);

                            // overwrite default if some container is using some other name
                            _originPartName = targetUri;
                            _originPart = p;
                            _originPartExists = true;
                        }
                    }
                }
                finally

View on GitHub (pinned to 81131a70a4)