dotnet/wpf · error · FileFormatException
SR.PackageSignatureCorruption
Error message
SR.PackageSignatureCorruption
What it means
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.
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.
Example fix
// before
mgr.RemoveSignature(sigUri); // FileFormatException on external relationship
// after
try { mgr.RemoveSignature(sigUri); }
catch (FileFormatException ex)
{
log.Error("Signature relationships corrupted; cannot remove signature", ex);
} Defensive patterns
Strategy: try-catch
Validate before calling
foreach (var r in originPart.GetRelationships())
if (r.TargetMode == TargetMode.External)
throw new InvalidOperationException("Origin part contains external signature relationships; package corrupt."); Try / catch
try { mgr.RemoveSignature(sigUri); }
catch (FileFormatException) { /* signature relationship corrupted — rebuild package */ } Prevention
- 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.
When it happens
Trigger: RemoveSignature/RemoveAllSignatures traversal encountering a signature relationship in the origin part whose TargetMode is External rather than Internal — the signature part cannot be resolved.
Common situations: Signature origin parts edited by hand or by non-conformant tools, packages damaged in transit, or relationships retargeted to external URIs by post-processing.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Signature structures are corrupted in this package.
- Signature structures are corrupted in this package.
- ' ' ID is not a valid XSD ID.
- Cannot remove signature from read-only file.
- Document contains multiple Rights Management Encryption…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/4c46c0f33df656e5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignatureManager.cs:1136
_container.DeleteRelationship(r.Id);
return true;
}
/// <summary>
/// Deletes any relationship to the given signature from the signature origin
/// </summary>
/// <param name="r">relationship from origin</param>
/// <param name="signatureUri">signatureUri</param>
/// <returns>true</returns>
private bool DeleteRelationshipToSignature(PackageRelationship r, Object signatureUri)
{
Uri uri = signatureUri as Uri;
Debug.Assert(uri != null, "Improper use of delegate - context must be Uri");
// don't resolve if external
if (r.TargetMode != TargetMode.Internal)
throw new FileFormatException(SR.PackageSignatureCorruption);
if (PackUriHelper.ComparePartUri(PackUriHelper.ResolvePartUri(r.SourceUri, r.TargetUri), uri) == 0)
{
OriginPart.DeleteRelationship(r.Id); // don't break early in case there are redundant relationships
}
return true;
}
private void DeleteOriginPart()
{
try
{
// remove all relationships of the type "package-to-signature-origin"
SafeVisitRelationships(_container.GetRelationshipsByType(_originRelationshipType),
DeleteRelationshipOfTypePackageToOriginVisitor);
_container.DeletePart(_originPartName);View on GitHub (pinned to 81131a70a4)