{"record":{"id":"f10bb8b5bfcd677f","repo":"dotnet/wpf","slug":"sr-xpsvalidatingloaderduplicatereference","errorCode":null,"errorMessage":"SR.XpsValidatingLoaderDuplicateReference","messagePattern":"SR\\.XpsValidatingLoaderDuplicateReference","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XPSS0ValidatingLoader.cs","lineNumber":214,"sourceCode":"            }\n        }\n\n\n        internal static void AssertDocumentMode()\n        {   // Once switched to document mode, we stay there\n            _documentMode = true;\n        }\n\n\n        internal void UriHitHandler(int node,Uri uri)\n        {\n            if (_uniqueUriRef != null)\n            {\n                if (_uniqueUriRef.Contains(uri))\n                {\n                    if ((int)_uniqueUriRef[uri] != node)\n                    {\n                        throw new FileFormatException(SR.XpsValidatingLoaderDuplicateReference);\n                    }\n                }\n                else\n                {\n                    _uniqueUriRef.Add(uri, node);\n                }\n            }\n            Hashtable validResources = _validResources.Peek();\n            if (validResources!=null)\n            {\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)","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XPSS0ValidatingLoader.cs#L196-L232","documentation":"XPSS0ValidatingLoader.UriHitHandler throws FileFormatException (SR.XpsValidatingLoaderDuplicateReference) when the same resource URI is referenced from two different markup nodes in a schema that forbids multiple references to one URI (e.g. the FixedPage schema). Each target URI may be used from a single node; a second hit from a different node is a format violation.","triggerScenarios":"Loading an XPS part in strict document mode where _uniqueUriRef already contains the URI under a different node id ((int)_uniqueUriRef[uri] != node, XPSS0ValidatingLoader.cs:214) while XpsSchema.AllowsMultipleReferencesToSameUri is false for that MIME type.","commonSituations":"Hand-authored or third-party-generated XPS that reuses one image/font relationship from multiple elements; a generator bug sharing a single relationship instead of creating separate parts; package-merge tools that deduplicate resources without adjusting references.","solutions":["Create a separate resource part (and relationship) for each element needing the resource.","Rewrite markup so each URI reference originates from only one node.","Regenerate the XPS with a compliant producer that follows the single-reference rule.","If reuse is intended, store the resource under a schema/MIME type that allows multiple references."],"exampleFix":"// before\n<Image Source=\"/resources/1.png\"/><Image Source=\"/resources/1.png\"/> <!-- same URI twice -->\n\n// after\n<Image Source=\"/resources/1.png\"/><Image Source=\"/resources/2.png\"/> <!-- duplicate part per reference -->","handlingStrategy":"validation","validationCode":"// detect reused source URIs within a FixedDocument before loading\nvar seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);\nforeach (var src in pageXml.Descendants().Select(e => (string)e.Attribute(\"Source\")).Where(s => s != null))\n    if (!seen.Add(src)) throw new InvalidOperationException($\"Duplicate resource reference: {src}\");","typeGuard":null,"tryCatchPattern":"try\n{\n    obj = loader.Load(stream, parentUri, pc, mimeType);\n}\ncatch (FileFormatException ex)\n{\n    // duplicate reference: deduplicate parts or split references before retry\n}","preventionTips":["Emit one resource part per element reference in FixedPage markup","Avoid resource deduplication tools that share relationships across nodes","Know which XPS schemas disallow repeated URI references","Validate generated pages for repeated Source/FontUri values"],"tags":["xps","file-format","validation","duplicate-reference"],"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"}