dotnet/wpf · error · XpsPackagingException

ReachPackaging_InvalidStartingPart

Error message

ReachPackaging_InvalidStartingPart

What it means

GetFixedDocumentSequence throws this XpsPackagingException when the package's starting part exists but its content type is not a valid root type (not a FixedDocumentSequence/FixedDocument content type). The package's starting part is malformed or is not a recognized XPS root.

Solutions

  1. Ensure the package contains a valid starting part (FixedDocumentSequence or FixedDocument) before reading
  2. Check CurrentXpsManager.StartingPart first; the method legitimately returns null when there is no starting part
  3. Verify the package was saved correctly and is not truncated or empty
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Packaging/XpsDocument.cs:605 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/01dd3d7166f75984. Report an issue: GitHub.

Appendix: source

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

            if (!IsReader)
            {
                throw new XpsPackagingException(SR.ReachPackaging_NotOpenForReading);
            }

            if (null == Uri)
            {
                throw new XpsPackagingException(SR.ReachPackaging_PackageUriNull);
            }

            if (CurrentXpsManager.StartingPart == null)
            {
                return null;
            }

            ContentType startPartType = CurrentXpsManager.StartingPart.ValidatedContentType();
            if (!startPartType.AreTypeAndSubTypeEqual(XpsS0Markup.DocumentSequenceContentType))
            {
                 throw new XpsPackagingException(SR.ReachPackaging_InvalidStartingPart);
            }
            ParserContext parserContext = new ParserContext
            {
                BaseUri = PackUriHelper.Create(Uri, CurrentXpsManager.StartingPart.Uri)
            };

            Uri packageUri = PackUriHelper.GetPackageUri(parserContext.BaseUri);

            Uri previousPackageUri = XpsLoadingContext.ActivePackageUri;
            
            // Establish XPS package context so that ambient-check sinks
            // (BitmapImage, BitmapDecoder, ColorContext, FontSource, PixelShader)
            // see the correct package origin during .fdseq parsing.
            XpsLoadingContext.ActivePackageUri = packageUri;
            try
            {
                object fixedObject = XamlReader.Load(CurrentXpsManager.StartingPart.GetStream(), parserContext, useRestrictiveXamlReader: true);
                if (!(fixedObject is FixedDocumentSequence))

View on GitHub (pinned to 81131a70a4)