dotnet/wpf · error · FileFormatException
SR.XpsValidatingLoaderDuplicateReference
Error message
SR.XpsValidatingLoaderDuplicateReference
What it means
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.
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.
Example fix
// before <Image Source="/resources/1.png"/><Image Source="/resources/1.png"/> <!-- same URI twice --> // after <Image Source="/resources/1.png"/><Image Source="/resources/2.png"/> <!-- duplicate part per reference -->
Defensive patterns
Strategy: validation
Validate before calling
// detect reused source URIs within a FixedDocument before loading
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var src in pageXml.Descendants().Select(e => (string)e.Attribute("Source")).Where(s => s != null))
if (!seen.Add(src)) throw new InvalidOperationException($"Duplicate resource reference: {src}"); Try / catch
try
{
obj = loader.Load(stream, parentUri, pc, mimeType);
}
catch (FileFormatException ex)
{
// duplicate reference: deduplicate parts or split references before retry
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- SR.XpsValidatingLoaderDiscardControlHasIncorrectType
- SR.XpsValidatingLoaderMoreThanOneThumbnailInPackage
- SR.XpsValidatingLoaderUnlistedResource
- SR.XpsValidatingLoaderUnsupportedMimeType
- SR.XpsValidatingLoaderUriNotInSamePackage
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/f10bb8b5bfcd677f.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XPSS0ValidatingLoader.cs:214
}
}
internal static void AssertDocumentMode()
{ // Once switched to document mode, we stay there
_documentMode = true;
}
internal void UriHitHandler(int node,Uri uri)
{
if (_uniqueUriRef != null)
{
if (_uniqueUriRef.Contains(uri))
{
if ((int)_uniqueUriRef[uri] != node)
{
throw new FileFormatException(SR.XpsValidatingLoaderDuplicateReference);
}
}
else
{
_uniqueUriRef.Add(uri, node);
}
}
Hashtable validResources = _validResources.Peek();
if (validResources!=null)
{
if (!validResources.ContainsKey(uri))
{
// The hashtable is case sensitive, packuris are not, so if we do not find in hashtable,
// do true comparison and add when found for next time...
bool found = false;
foreach (Uri resUri in validResources.Keys)
{
if (PackUriHelper.ComparePackUri(resUri,uri) == 0)View on GitHub (pinned to 81131a70a4)