{"record":{"id":"e095eb7126618fef","repo":"dotnet/wpf","slug":"resource-xpspackageboundaryviolation","errorCode":null,"errorMessage":"Resource_XpsPackageBoundaryViolation","messagePattern":"Resource_XpsPackageBoundaryViolation","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/XpsLoadingContext.cs","lineNumber":160,"sourceCode":"                }\n                else\n                {\n                    return true;\n                }\n            }\n\n            return IsSamePackageUri(parentUri, resolvedUri);\n        }\n\n        /// <summary>\n        /// Throws <see cref=\"FileFormatException\"/> when\n        /// <see cref=\"IsAllowedPackageRelativeUri\"/> returns false.\n        /// </summary>\n        internal static void EnforcePackageRelativeUri(Uri parentUri, Uri resolvedUri)\n        {\n            if (!IsAllowedPackageRelativeUri(parentUri, resolvedUri))\n            {\n                throw new FileFormatException(SR.Resource_XpsPackageBoundaryViolation);\n            }\n        }\n\n        /// <summary>\n        /// Returns true when <paramref name=\"uri\"/> is an absolute pack:// URI\n        /// whose authority encodes a real XPS package (i.e. an escaped package\n        /// file URI). Returns false for null / non-pack URIs and for the two\n        /// WPF-internal pack authorities \"application:\" and \"siteoforigin:\",\n        /// which are not XPS packages.\n        /// </summary>\n        internal static bool IsXpsPackageContext(Uri uri)\n        {\n            if (uri == null || !uri.IsAbsoluteUri)\n            {\n                return false;\n            }\n\n            if (!string.Equals(uri.Scheme, PackUriHelper.UriSchemePack, StringComparison.OrdinalIgnoreCase))","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/MS/internal/XpsLoadingContext.cs#L142-L178","documentation":"XpsLoadingContext.EnforcePackageRelativeUri throws FileFormatException with SR.Resource_XpsPackageBoundaryViolation when a resolved URI is not an allowed package-relative URI for the parent document. This enforces XPS package boundaries: resources must reference content inside the same XPS package rather than escaping to another package or an external location.","triggerScenarios":"Loading an XPS/FixedDocument where a part's relative URI resolves to an absolute pack:// URI whose authority encodes a different XPS package, or otherwise fails IsAllowedPackageRelativeUri checks (e.g. cross-package references, invalid authority encoding).","commonSituations":"Hand-crafted or tool-mangled XPS files containing absolute pack URIs in FixedPage.Source or image Sources, documents merged/relocated across packages, or generated XPS with incorrectly escaped part names.","solutions":["Fix the XPS content: replace cross-package or absolute pack:// references with package-relative part URIs (e.g. /Documents/1/Pages/1.fpage).","Regenerate the XPS with a conforming producer so all resource references are relative and within the same package.","If intentional external references are needed, load them via supported APIs instead of embedding them in the XPS.","Catch FileFormatException during XpsDocument load and report the offending part to the document author."],"exampleFix":"// before (inside FixedPage.xaml of an XPS)\n<Image Source=\"pack://uuid:other-package-uuid/documents/1/img.png\" />\n// after\n<Image Source=\"../../Resources/img.png\" />","handlingStrategy":"validation","validationCode":"bool IsPackageRelative(Uri uri)\n{\n    if (!uri.IsAbsoluteUri) return true; // relative part URI is fine\n    if (uri.Scheme != \"pack\") return false;\n    // must encode the same package as the parent document\n    return XpsLoadingContext.IsAllowedPackageRelativeUri(parentUri, uri);\n}","typeGuard":"bool IsRelativePartUri(Uri u) => !u.IsAbsoluteUri || (u.IsAbsoluteUri && u.Scheme == \"pack\");","tryCatchPattern":"try { XpsLoadingContext.EnforcePackageRelativeUri(parentUri, resolvedUri); }\ncatch (FileFormatException ex)\n{ throw new InvalidOperationException(\"XPS part references outside its package: \" + resolvedUri, ex); }","preventionTips":["Author XPS with package-relative part URIs, never absolute pack:// cross-package references.","Validate XPS files with a conforming producer before distribution.","Do not hand-edit or merge XPS packages without rewriting part references."],"tags":["file-format-exception","xps","pack-uri","document-loading","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}