dotnet/wpf · error · NullReferenceException

signature.PackageSignature.SignaturePart

Error message

signature.PackageSignature.SignaturePart

What it means

RemoveSignature throws this NullReferenceException when signature.PackageSignature.SignaturePart is null — the signature exists but has no associated signature part in the package, so the part to remove cannot be located. This is a defensive guard against a corrupt or incomplete signature object.

Solutions

  1. Verify the signature has an associated SignaturePart (it was actually committed to the package) before removal
  2. Re-sign or re-open the package so the signature's SignaturePart exists
  3. Check signature.PackageSignature.SignaturePart for null before calling RemoveSignature
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsDocument.cs:477 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsDocument.cs:477

        /// The signature to be removed
        /// </param>
        /// <exception cref="ArgumentNullException">signature is null.</exception>
        public
        void
        RemoveSignature(
            XpsDigitalSignature signature
            )
        {
            CheckDisposed();

            ArgumentNullException.ThrowIfNull(signature);
            if (null == signature.PackageSignature)
            {
                throw new NullReferenceException("signature.PackageSignature");
            }
            if (null == signature.PackageSignature.SignaturePart)
            {
                throw new NullReferenceException("signature.PackageSignature.SignaturePart");
            }
            if( CurrentXpsManager == null )
            {
                throw new InvalidOperationException(SR.ReachPackaging_DocumentWasClosed);
            }
            PackageDigitalSignatureManager packageSignatures = new PackageDigitalSignatureManager(CurrentXpsManager.MetroPackage);
            packageSignatures.RemoveSignature(signature.PackageSignature.SignaturePart.Uri );
            _reachSignatures = null;
            _reachSignatureList = null;
            EnsureSignatures();
}

        /// <summary>
        /// This method adds a thumbnail to the current Xps package.
        ///
        /// There can only be one thumbnail attached to the pakcage.
        ///  Calling this method when there
        /// is already a starting part causes InvalidOperationException to be

View on GitHub (pinned to 81131a70a4)