{"record":{"id":"4c46c0f33df656e5","repo":"dotnet/wpf","slug":"sr-packagesignaturecorruption-packagedigitalsignaturemanager","errorCode":null,"errorMessage":"SR.PackageSignatureCorruption","messagePattern":"SR\\.PackageSignatureCorruption","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs","lineNumber":1136,"sourceCode":"                _container.DeleteRelationship(r.Id);\n\n            return true;\n        }\n\n        /// <summary>\n        /// Deletes any relationship to the given signature from the signature origin\n        /// </summary>\n        /// <param name=\"r\">relationship from origin</param>\n        /// <param name=\"signatureUri\">signatureUri</param>\n        /// <returns>true</returns>\n        private bool DeleteRelationshipToSignature(PackageRelationship r, Object signatureUri)\n        {\n            Uri uri = signatureUri as Uri;\n            Debug.Assert(uri != null, \"Improper use of delegate - context must be Uri\");\n\n            // don't resolve if external\n            if (r.TargetMode != TargetMode.Internal)\n                throw new FileFormatException(SR.PackageSignatureCorruption);\n\n            if (PackUriHelper.ComparePartUri(PackUriHelper.ResolvePartUri(r.SourceUri, r.TargetUri), uri) == 0)\n            {\n                OriginPart.DeleteRelationship(r.Id);    // don't break early in case there are redundant relationships\n            }\n\n            return true;\n        }\n\n        private void DeleteOriginPart()\n        {\n            try\n            {\n                // remove all relationships of the type \"package-to-signature-origin\"\n                SafeVisitRelationships(_container.GetRelationshipsByType(_originRelationshipType), \n                    DeleteRelationshipOfTypePackageToOriginVisitor);\n\n                _container.DeletePart(_originPartName);","sourceCodeStart":1118,"sourceCodeEnd":1154,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs#L1118-L1154","documentation":"DeleteRelationshipToSignature removes origin-part relationships pointing at a signature being deleted; if such a relationship has an external target instead of an internal signature part, it throws FileFormatException (SR.PackageSignatureCorruption), signaling corrupted signature structures in the package.","triggerScenarios":"RemoveSignature/RemoveAllSignatures traversal encountering a signature relationship in the origin part whose TargetMode is External rather than Internal — the signature part cannot be resolved.","commonSituations":"Signature origin parts edited by hand or by non-conformant tools, packages damaged in transit, or relationships retargeted to external URIs by post-processing.","solutions":["Catch FileFormatException around the removal API and mark the package's signature block as unusable.","Re-create/re-save the package with a conformant producer to rebuild internal signature relationships.","When writing signature infrastructure, always add signature relationships with TargetMode.Internal."],"exampleFix":"// before\nmgr.RemoveSignature(sigUri); // FileFormatException on external relationship\n// after\ntry { mgr.RemoveSignature(sigUri); }\ncatch (FileFormatException ex)\n{\n    log.Error(\"Signature relationships corrupted; cannot remove signature\", ex);\n}","handlingStrategy":"try-catch","validationCode":"foreach (var r in originPart.GetRelationships())\n    if (r.TargetMode == TargetMode.External)\n        throw new InvalidOperationException(\"Origin part contains external signature relationships; package corrupt.\");","typeGuard":null,"tryCatchPattern":"try { mgr.RemoveSignature(sigUri); }\ncatch (FileFormatException) { /* signature relationship corrupted — rebuild package */ }","preventionTips":["Never set TargetMode.External on signature relationships inside the origin part.","Catch FileFormatException and stop signature processing rather than retrying.","Round-trip test signed packages through your producer pipeline to catch corruption early."],"tags":["wpf","packaging","corruption","file-format","digital-signature"],"backgroundTag":"schema-validation-failed","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}