{"record":{"id":"6a2de423276cf4ab","repo":"dotnet/wpf","slug":"sr-xpsvalidatingloaderrestrictedfonthasincorrecttype","errorCode":null,"errorMessage":"SR.XpsValidatingLoaderRestrictedFontHasIncorrectType","messagePattern":"SR\\.XpsValidatingLoaderRestrictedFontHasIncorrectType","errorType":"exception","errorClass":"FileFormatException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs","lineNumber":604,"sourceCode":"            }\n\n            // FixedDocument only has restricted font relationships\n            if (_fixedDocumentContentType.AreTypeAndSubTypeEqual(mimeType))\n            {\n                // Check if target of restricted font relationship is present and is actually a font\n                checkRels = part.GetRelationshipsByType(_restrictedFontRel);\n                foreach (PackageRelationship rel in checkRels)\n                {\n                    // Check for existence and type\n                    Uri targetUri = PackUriHelper.ResolvePartUri(partUri, rel.TargetUri);\n                    Uri absTargetUri = PackUriHelper.Create(packageUri, targetUri);\n\n                    PackagePart targetPart = package.GetPart(targetUri);\n\n                    if (!_fontContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)) &&\n                            !_obfuscatedContentType.AreTypeAndSubTypeEqual(new ContentType(targetPart.ContentType)))\n                    {\n                        throw new FileFormatException(SR.XpsValidatingLoaderRestrictedFontHasIncorrectType);\n                    }\n                }\n            }\n\n            // check constraints for XPS fixed payload start part\n            if (_fixedDocumentSequenceContentType.AreTypeAndSubTypeEqual(mimeType))\n            {\n                // This is the XPS payload root part. We also should check if the Package only has at most one discardcontrol...\n                checkRels = package.GetRelationshipsByType(_discardControlRel);\n                count = 0;\n                foreach (PackageRelationship rel in checkRels)\n                {\n                    count++;\n                    if (count > 1)\n                    {\n                        throw new FileFormatException(SR.XpsValidatingLoaderMoreThanOneDiscardControlInPackage);\n                    }\n","sourceCodeStart":586,"sourceCodeEnd":622,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/FixedSchema.cs#L586-L622","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","Re-point the restricted-font relationship at the correct font part.","Re-obfuscate/re-embed the font with the proper content type and GUID-named part if subsetting was applied.","Verify font relationships on FixedDocument parts with GetRelationshipsByType before loading."],"exampleFix":"// before\nPackagePart font = pkg.CreatePart(fontUri, \"application/x-font-ttf\");\n// after\nPackagePart font = pkg.CreatePart(fontUri, \"application/vnd.ms-package.obfuscated-opentype\");","handlingStrategy":"validation","validationCode":"const string fontType = \"application/vnd.ms-opentype\";\nconst string obfuscatedType = \"application/vnd.ms-package.obfuscated-opentype\";\nforeach (var rel in fixedDocPart.GetRelationshipsByType(restrictedFontRel)) {\n    var target = package.GetPart(PackUriHelper.ResolvePartUri(fixedDocPart.Uri, rel.TargetUri));\n    var ct = target.ContentType;\n    if (!ct.Equals(fontType, StringComparison.OrdinalIgnoreCase) &&\n        !ct.Equals(obfuscatedType, StringComparison.OrdinalIgnoreCase))\n        throw new InvalidDataException($\"Restricted font rel target {target.Uri} has invalid type {ct}\");\n}","typeGuard":"static bool IsCompliantFontPart(PackagePart p) =>\n    p.ContentType.Equals(\"application/vnd.ms-opentype\", StringComparison.OrdinalIgnoreCase) ||\n    p.ContentType.Equals(\"application/vnd.ms-package.obfuscated-opentype\", StringComparison.OrdinalIgnoreCase);","tryCatchPattern":"try { loader.Load(packageStream); }\ncatch (FileFormatException ex) { // wrong font part type: fix content types then retry\n    FixFontPartContentTypes(packageStream); loader.Load(packageStream); }","preventionTips":["Embed fonts as vnd.ms-opentype; subsetted fonts must be obfuscated (vnd.ms-package.obfuscated-opentype) with GUID part names.","Add font MIME entries to [Content_Types].xml when building packages.","Never retarget font relationships at non-font assets."],"tags":["xps","font","content-type","validation"],"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"}