dotnet/wpf · error · InvalidOperationException

Signature was deleted.

Error message

Signature was deleted.

What it means

Once a PackageDigitalSignature has been removed (invalidated), nearly all of its properties (SignedParts, SignedRelationshipSelectors, SignaturePart, Signer, SigningTime, TimeFormat) call ThrowIfInvalidated and throw InvalidOperationException reporting the signature was deleted. The object remains referenced but is no longer usable.

Solutions

  1. Read all needed properties (Signer, SigningTime, etc.) before calling RemoveSignature
  2. Stop using signature objects once removed; re-fetch manager.Signatures for current valid signatures
  3. Guard property access with the signature's invalid state or a try/catch on InvalidOperationException

Example fix

// before
foreach (var sig in manager.Signatures.ToList())
{
    manager.RemoveSignature(sig);
    Console.WriteLine(sig.SigningTime); // InvalidOperationException
}
// after
foreach (var sig in manager.Signatures.ToList())
{
    Console.WriteLine(sig.SigningTime); // read first
    manager.RemoveSignature(sig);
}
Defensive patterns

Strategy: validation

Validate before calling

// read needed data before RemoveSignature
var time = sig.SigningTime;
manager.RemoveSignature(sig);
// after removal, do not touch sig properties

Try / catch

try { var t = sig.SigningTime; }
catch (InvalidOperationException) { /* signature was deleted: refetch from manager.Signatures */ }

Prevention

When it happens

Trigger: Holding a PackageDigitalSignature reference and calling PackageDigitalSignatureManager.RemoveSignature (which marks it invalid), then reading any of its properties; enumerating cached signatures after removal.

Common situations: Iterating manager.Signatures, removing signatures inside the loop, then reading properties of already-removed signatures; keeping signature objects in collections across RemoveSignature calls.

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/49889b1bf57aabec. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/IO/Packaging/PackageDigitalSignature.cs:414

            _certificatePart = certificatePart;
        }

        #endregion

        #region Private Methods

        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------
        /// <summary>
        /// ThrowIfInvalidated - check on each access
        /// </summary>
        private void ThrowIfInvalidated()
        {
            if (_invalid)
                throw new InvalidOperationException(SR.SignatureDeleted);
        }

        #endregion Private Methods

        //------------------------------------------------------
        //
        //  Private Fields
        //
        //------------------------------------------------------
        private PackageDigitalSignatureManager                     _manager;
        private XmlDigitalSignatureProcessor                       _processor;
        private CertificatePart                                    _certificatePart;
        private ReadOnlyCollection<Uri>                            _signedParts;
        private ReadOnlyCollection<PackageRelationshipSelector>    _signedRelationshipSelectors;
        private bool                                               _alreadyLookedForCertPart;
        private bool                                               _invalid;   // have we been invalidated?
    }
}

View on GitHub (pinned to 81131a70a4)