dotnet/wpf · error · FileFormatException

SR.XpsValidatingLoaderRestrictedFontHasIncorrectType

Error message

SR.XpsValidatingLoaderRestrictedFontHasIncorrectType

What it means

A FixedDocument's restricted-font relationship must target a part of type application/vnd.ms-opentype (font) or application/vnd.ms-package.obfuscated-opentype (obfuscated font). If the target part's Content Type matches neither, ValidateRelationships throws FileFormatException because restricted font relationships may only reference font parts.

Solutions

  1. Set the font part's Content Type to application/vnd.ms-opentype, or application/vnd.ms-package.obfuscated-opentype if the font is obfuscated (as required for subsetted fonts in XPS).
  2. Re-point the restricted-font relationship at the correct font part.
  3. Re-obfuscate/re-embed the font with the proper content type and GUID-named part if subsetting was applied.
  4. Verify font relationships on FixedDocument parts with GetRelationshipsByType before loading.

Example fix

// before
PackagePart font = pkg.CreatePart(fontUri, "application/x-font-ttf");
// after
PackagePart font = pkg.CreatePart(fontUri, "application/vnd.ms-package.obfuscated-opentype");
Defensive patterns

Strategy: validation

Validate before calling

const string fontType = "application/vnd.ms-opentype";
const string obfuscatedType = "application/vnd.ms-package.obfuscated-opentype";
foreach (var rel in fixedDocPart.GetRelationshipsByType(restrictedFontRel)) {
    var target = package.GetPart(PackUriHelper.ResolvePartUri(fixedDocPart.Uri, rel.TargetUri));
    var ct = target.ContentType;
    if (!ct.Equals(fontType, StringComparison.OrdinalIgnoreCase) &&
        !ct.Equals(obfuscatedType, StringComparison.OrdinalIgnoreCase))
        throw new InvalidDataException($"Restricted font rel target {target.Uri} has invalid type {ct}");
}

Type guard

static bool IsCompliantFontPart(PackagePart p) =>
    p.ContentType.Equals("application/vnd.ms-opentype", StringComparison.OrdinalIgnoreCase) ||
    p.ContentType.Equals("application/vnd.ms-package.obfuscated-opentype", StringComparison.OrdinalIgnoreCase);

Try / catch

try { loader.Load(packageStream); }
catch (FileFormatException ex) { // wrong font part type: fix content types then retry
    FixFontPartContentTypes(packageStream); loader.Load(packageStream); }

Prevention

When it happens

Trigger: Loading an XPS package where a FixedDocument part has a restricted-font relationship pointing to a part declared with some other Content Type (e.g. application/octet-stream, application/x-font-ttf, an XML or image part) — the double AreTypeAndSubTypeEqual check fails.

Common situations: Fonts added to the package as raw resources with a generic MIME type instead of vnd.ms-opentype/obfuscated-opentype; package tools that re-embed fonts with wrong content types; relationship retargeting after a font part was replaced by a different asset.

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


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs:604

            }

            // FixedDocument only has restricted font relationships
            if (_fixedDocumentContentType.AreTypeAndSubTypeEqual(mimeType))
            {
                // Check if target of restricted font relationship is present and is actually a font
                checkRels = part.GetRelationshipsByType(_restrictedFontRel);
                foreach (PackageRelationship rel in checkRels)
                {
                    // Check for existence and type
                    Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri);
                    Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);

                    PackagePart targetPart = package.GetPart(targetUri);

                    if (!_fontContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)) &&
                            !_obfuscatedContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))
                    {
                        throw new FileFormatException(SR.XpsValidatingLoaderRestrictedFontHasIncorrectType);
                    }
                }
            }

            // check constraints for XPS fixed payload start part
            if (_fixedDocumentSequenceContentType.AreTypeAndSubTypeEqual(mimeType))
            {
                // This is the XPS payload root part. We also should check if the Package only has at most one discardcontrol...
                checkRels = package.GetRelationshipsByType(_discardControlRel);
                count = 0;
                foreach (PackageRelationship rel in checkRels)
                {
                    count++;
                    if (count > 1)
                    {
                        throw new FileFormatException(SR.XpsValidatingLoaderMoreThanOneDiscardControlInPackage);
                    }

View on GitHub (pinned to 81131a70a4)