dotnet/wpf · error · FileFormatException

SR.XpsValidatingLoaderUnlistedResource

Error message

SR.XpsValidatingLoaderUnlistedResource

What it means

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.

Solutions

  1. Add the missing required-resource PackageRelationship (type http://schemas.microsoft.com/xps/2005/06/required-resource) from the consuming part to the target part.
  2. Remove the dangling reference or element pointing to the unlisted resource.
  3. Regenerate the XPS package with a compliant producer so references and relationships stay consistent.
  4. Verify each referenced part exists and is listed among required resources before loading.

Example fix

// before: page references /fonts/1.odttc with no required-resource relationship
<Glyphs FontUri="/resources/fonts/1.odttc" .../>

// after: add to the part's _rels
<Relationship Type="http://schemas.microsoft.com/xps/2005/06/required-resource" Target="/resources/fonts/1.odttc"/>
Defensive patterns

Strategy: validation

Validate before calling

// confirm every referenced resource has a required-resource relationship
var required = part.GetRelationshipsByType("http://schemas.microsoft.com/xps/2005/06/required-resource")
    .Select(r => System.IO.Packaging.PackUriHelper.ResolvePartUri(partUri, r.TargetUri).ToString())
    .ToHashSet(StringComparer.OrdinalIgnoreCase);
bool allListed = referencedUris.All(u => required.Contains(u));

Try / catch

try
{
    obj = loader.Load(stream, parentUri, pc, mimeType);
}
catch (FileFormatException ex)
{
    // unlisted resource: add the missing relationship or drop the reference
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/2b73d86482932811. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/XPSS0ValidatingLoader.cs:242

            {
                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)
                        {
                            validResources.Add(uri, validResources[resUri]);
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        throw new FileFormatException(SR.XpsValidatingLoaderUnlistedResource);
                    }
                }
                if (!(bool)validResources[uri])
                {
                    throw new FileFormatException(SR.XpsValidatingLoaderUnsupportedMimeType);
                }
            }
        }

        private static Stack<Hashtable> _validResources = new Stack<Hashtable>();

        private Hashtable _uniqueUriRef;

        private
        static 
        bool _documentMode          = false;

        private 

View on GitHub (pinned to 81131a70a4)