dotnet/wpf · error · XpsPackagingException

PackagePart already has associated Thumbnail.

Error message

PackagePart already has associated Thumbnail.

What it means

XpsManager.AddThumbnail throws this XpsPackagingException when an XPS package part already has an associated thumbnail. The XPS specification allows at most one thumbnail part per package or FixedDocumentSequence/FixedDocument element, so attempting to add a second thumbnail (via AddThumbnail with a non-null oldThumbnail) is rejected.

Solutions

  1. Remove or delete the existing thumbnail before adding a new one (e.g. delete the old XpsThumbnail part from the package).
  2. Only pass null as oldThumbnail when creating a brand-new thumbnail for a parent that has none.
  3. Check whether the parent already has a thumbnail and skip AddThumbnail if so.
  4. If re-writing a package, create a fresh XpsDocument/package instead of adding thumbnails to a pre-existing one.

Example fix

// before
XpsThumbnail thumb = manager.AddThumbnail(XpsImageType.PngImageType, node, existingThumb);
// after
if (existingThumb == null)
{
    XpsThumbnail thumb = manager.AddThumbnail(XpsImageType.PngImageType, node, null);
}
else
{
    // keep or replace the existing thumbnail part first
}
Defensive patterns

Strategy: validation

Validate before calling

if (node != null && nodeThumbnail != null) { /* thumbnail already exists: skip or replace */ }

Try / catch

catch (XpsPackagingException ex) { /* handle: thumbnail already present */ }

Prevention

When it happens

Trigger: Calling AddThumbnail(imageType, parent, oldThumbnail) where oldThumbnail is not null — i.e. the parent node (package, document sequence, or document) already owns an XpsThumbnail and the caller is trying to replace/add another instead of committing and clearing the old one.

Common situations: Re-serializing an existing XPS document that already contains a thumbnail without first removing or consuming the old thumbnail; calling AddThumbnail twice in a custom XPS writing pipeline; resuming an interrupted save where the thumbnail was already created.

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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsManager.cs:720

            //
            PackagePart propertiesPart = GetDocumentPropertiesPart();

            if( propertiesPart == null )
            {
                propertiesPart = GenerateUniquePart(XpsS0Markup.CoreDocumentPropertiesType );
                _metroPackage.CreateRelationship(propertiesPart.Uri, TargetMode.Internal, XpsS0Markup.CorePropertiesRelationshipType );
            }
            return propertiesPart;
        }

        public
        XpsThumbnail
        AddThumbnail(XpsImageType imageType, INode parent, XpsThumbnail oldThumbnail )
        {
            XpsThumbnail newThumbnail = null;
            if( oldThumbnail != null )
            {
                throw new XpsPackagingException(SR.ReachPackaging_AlreadyHasThumbnail);
            }    
            if( !( imageType == XpsImageType.JpegImageType ||
                    imageType == XpsImageType.PngImageType ) )
            {
                throw new XpsPackagingException(SR.ReachPackaging_UnsupportedThumbnailImageType);
            }   
            newThumbnail = new XpsThumbnail(this,
                                        parent,
                                        GenerateUniquePart(ImageTypeToString(imageType))
                                        );
            return newThumbnail;
        }

        public
        XpsThumbnail
        EnsureThumbnail( INode parent, PackagePart part )
        {
            XpsThumbnail thumbnail = null;

View on GitHub (pinned to 81131a70a4)