{"record":{"id":"2b73d86482932811","repo":"dotnet/wpf","slug":"sr-xpsvalidatingloaderunlistedresource","errorCode":null,"errorMessage":"SR.XpsValidatingLoaderUnlistedResource","messagePattern":"SR\\.XpsValidatingLoaderUnlistedResource","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XPSS0ValidatingLoader.cs","lineNumber":242,"sourceCode":"            {\n                if (!validResources.ContainsKey(uri))\n                {\n                    // The hashtable is case sensitive, packuris are not, so if we do not find in hashtable,\n                    // do true comparison and add when found for next time...\n                    bool found = false;\n                    foreach (Uri resUri in validResources.Keys)\n                    {\n                        if (PackUriHelper.ComparePackUri(resUri,uri) == 0)\n                        {\n                            validResources.Add(uri, validResources[resUri]);\n                            found = true;\n                            break;\n                        }\n                    }\n\n                    if (!found)\n                    {\n                        throw new FileFormatException(SR.XpsValidatingLoaderUnlistedResource);\n                    }\n                }\n                if (!(bool)validResources[uri])\n                {\n                    throw new FileFormatException(SR.XpsValidatingLoaderUnsupportedMimeType);\n                }\n            }\n        }\n\n        private static Stack<Hashtable> _validResources = new Stack<Hashtable>();\n\n        private Hashtable _uniqueUriRef;\n\n        private\n        static \n        bool _documentMode          = false;\n\n        private ","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XPSS0ValidatingLoader.cs#L224-L260","documentation":"XPSS0ValidatingLoader.UriHitHandler throws FileFormatException (SR.XpsValidatingLoaderUnlistedResource) when markup references a resource URI that is not in the part's valid/required resources list. In strict XPS mode every remote URI hit must resolve to a resource registered from the part's required-resource relationships; anything unlisted is rejected.","triggerScenarios":"Loading an XPS part in document mode where an element references a URI that is absent from the validResources table and has no case-insensitive match via PackUriHelper.ComparePackUri (XPSS0ValidatingLoader.cs:242) — i.e. no 'required-resource' relationship declared it.","commonSituations":"Hand-edited XPS adding a resource reference without the corresponding relationship; producer tools emitting references to parts not listed as required resources; stripped or incomplete _rels entries after package manipulation; a referenced part missing from the package entirely.","solutions":["Add the missing required-resource PackageRelationship (type http://schemas.microsoft.com/xps/2005/06/required-resource) from the consuming part to the target part.","Remove the dangling reference or element pointing to the unlisted resource.","Regenerate the XPS package with a compliant producer so references and relationships stay consistent.","Verify each referenced part exists and is listed among required resources before loading."],"exampleFix":"// before: page references /fonts/1.odttc with no required-resource relationship\n<Glyphs FontUri=\"/resources/fonts/1.odttc\" .../>\n\n// after: add to the part's _rels\n<Relationship Type=\"http://schemas.microsoft.com/xps/2005/06/required-resource\" Target=\"/resources/fonts/1.odttc\"/>","handlingStrategy":"validation","validationCode":"// confirm every referenced resource has a required-resource relationship\nvar required = part.GetRelationshipsByType(\"http://schemas.microsoft.com/xps/2005/06/required-resource\")\n    .Select(r => System.IO.Packaging.PackUriHelper.ResolvePartUri(partUri, r.TargetUri).ToString())\n    .ToHashSet(StringComparer.OrdinalIgnoreCase);\nbool allListed = referencedUris.All(u => required.Contains(u));","typeGuard":null,"tryCatchPattern":"try\n{\n    obj = loader.Load(stream, parentUri, pc, mimeType);\n}\ncatch (FileFormatException ex)\n{\n    // unlisted resource: add the missing relationship or drop the reference\n}","preventionTips":["Always pair every remote resource reference with a required-resource relationship","Never strip _rels entries when post-processing XPS packages","Check that all referenced parts exist in the package before loading","Generate XPS with tools that keep references and relationships in sync"],"tags":["xps","file-format","validation","missing-resource","package-relationship"],"backgroundTag":"resource-not-found","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"}