{"record":{"id":"ae8de4cf5382ddc3","repo":"dotnet/wpf","slug":"no-font-service-is-registered-with-resource-policy","errorCode":null,"errorMessage":"No font service is registered with resource policy.","messagePattern":"No font service is registered with resource policy\\.","errorType":"exception","errorClass":"XpsSerializationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/FontTypeConverter.cs","lineNumber":167,"sourceCode":"\n            PackageSerializationManager manager = (PackageSerializationManager)context.GetService(typeof(XpsSerializationManager));\n            //\n            // Ensure that we have a valid GlyphRun instance\n            //\n            GlyphRun fontGlyphRun = (GlyphRun)value;\n            if (fontGlyphRun == null)\n            {\n                throw new ArgumentException(SR.Format(SR.MustBeOfType, \"value\", \"GlyphRun\"));\n            }\n\n            //\n            // Obtain the font serialization service from the serlialization manager.\n            //\n            IServiceProvider resourceServiceProvider = manager.ResourcePolicy;\n            XpsFontSerializationService fontService = (XpsFontSerializationService)resourceServiceProvider.GetService(typeof(XpsFontSerializationService));\n            if (fontService == null)\n            {\n                throw new XpsSerializationException(SR.ReachSerialization_NoFontService);\n            }\n\n            //\n            // Retrieve the current font subsetter\n            //\n            XpsFontSubsetter fontSubsetter = fontService.FontSubsetter;\n\n            //\n            // Add the font subset to the font subsetter and retrieve a Uri\n            // to the font within the Xps package.\n            //\n            Uri resourceUri = fontSubsetter.ComputeFontSubset(fontGlyphRun);\n\n            Toolbox.EmitEvent(EventTrace.Event.WClientDRXConvertFontEnd);\n\n            return resourceUri;\n        }\n","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/FontTypeConverter.cs#L149-L185","documentation":"FontTypeConverter.ConvertTo embeds a GlyphRun font into an XPS package while serializing. It asks the serialization manager's ResourcePolicy for an XpsFontSerializationService; when none is registered (GetService returns null), the converter cannot subset or embed the font and throws XpsSerializationException with ReachSerialization_NoFontService. This indicates the serialization pipeline was created without the font resource service.","triggerScenarios":"Calling FontTypeConverter.ConvertTo with a context whose IServiceProvider.GetService(typeof(XpsSerializationManager)) returns a PackageSerializationManager whose ResourcePolicy has no XpsFontSerializationService registered — e.g. a custom or minimally-configured PackageSerializationManager used outside the standard XPS save pipeline.","commonSituations":"Custom XPS serialization hosts that construct PackageSerializationManager directly and forget to register resource services; using the converter in design-time or generic TypeConverter scenarios where no XPS serialization manager exists; partial reimplementation of the XpsSerializationManager stack.","solutions":["Use the standard XpsSerializationManager / XpsPackagingPipeline (e.g. via XpsDocumentWriter.SaveAsXaml) so the font serialization service is registered on the ResourcePolicy automatically.","If using a custom serialization manager, register an XpsFontSerializationService with the manager's ResourcePolicy before calling ConvertTo.","Wrap ConvertTo in a try-catch for XpsSerializationException and fall back to non-subsetted font embedding or surface a clear configuration error."],"exampleFix":"// before: custom manager with bare ResourcePolicy\nvar manager = new PackageSerializationManager();\nconverter.ConvertTo(context, culture, glyphRun, typeof(Uri));\n\n// after: go through the standard XPS serialization pipeline\nusing (XpsDocument doc = new XpsDocument(path, FileAccess.ReadWrite))\n{\n    XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);\n    writer.Write(fixedDocumentSequence); // registers font service internally\n}","handlingStrategy":"try-catch","validationCode":"var manager = (PackageSerializationManager)context.GetService(typeof(XpsSerializationManager));\nbool ok = manager?.ResourcePolicy?.GetService(typeof(XpsFontSerializationService)) != null;\nif (!ok) throw new InvalidOperationException(\"Font serialization requires XpsFontSerializationService on the ResourcePolicy.\");","typeGuard":"static bool HasFontService(IServiceProvider provider) =>\n    provider?.GetService(typeof(XpsFontSerializationService)) is XpsFontSerializationService;","tryCatchPattern":"try\n{\n    var uri = (Uri)converter.ConvertTo(context, culture, glyphRun, typeof(Uri));\n}\ncatch (XpsSerializationException ex) when (ex.Message.Contains(\"font service\"))\n{\n    // fall back to standard XPS pipeline or log a configuration error\n}","preventionTips":["Always serialize XPS content through XpsDocumentWriter rather than a hand-built PackageSerializationManager.","Verify the ResourcePolicy has font/image services registered before starting serialization.","Smoke-test custom serialization managers with a document containing a GlyphRun."],"tags":["wpf","xps","serialization","fonts","missing-service"],"backgroundTag":"missing-dependency","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"}