dotnet/wpf · error · XpsSerializationException

No font service is registered with resource policy.

Error message

No font service is registered with resource policy.

What it means

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.

Solutions

  1. Use the standard XpsSerializationManager / XpsPackagingPipeline (e.g. via XpsDocumentWriter.SaveAsXaml) so the font serialization service is registered on the ResourcePolicy automatically.
  2. If using a custom serialization manager, register an XpsFontSerializationService with the manager's ResourcePolicy before calling ConvertTo.
  3. Wrap ConvertTo in a try-catch for XpsSerializationException and fall back to non-subsetted font embedding or surface a clear configuration error.

Example fix

// before: custom manager with bare ResourcePolicy
var manager = new PackageSerializationManager();
converter.ConvertTo(context, culture, glyphRun, typeof(Uri));

// after: go through the standard XPS serialization pipeline
using (XpsDocument doc = new XpsDocument(path, FileAccess.ReadWrite))
{
    XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
    writer.Write(fixedDocumentSequence); // registers font service internally
}
Defensive patterns

Strategy: try-catch

Validate before calling

var manager = (PackageSerializationManager)context.GetService(typeof(XpsSerializationManager));
bool ok = manager?.ResourcePolicy?.GetService(typeof(XpsFontSerializationService)) != null;
if (!ok) throw new InvalidOperationException("Font serialization requires XpsFontSerializationService on the ResourcePolicy.");

Type guard

static bool HasFontService(IServiceProvider provider) =>
    provider?.GetService(typeof(XpsFontSerializationService)) is XpsFontSerializationService;

Try / catch

try
{
    var uri = (Uri)converter.ConvertTo(context, culture, glyphRun, typeof(Uri));
}
catch (XpsSerializationException ex) when (ex.Message.Contains("font service"))
{
    // fall back to standard XPS pipeline or log a configuration error
}

Prevention

When it happens

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

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

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/ReachFramework/Serialization/FontTypeConverter.cs:167

            PackageSerializationManager manager = (PackageSerializationManager)context.GetService(typeof(XpsSerializationManager));
            //
            // Ensure that we have a valid GlyphRun instance
            //
            GlyphRun fontGlyphRun = (GlyphRun)value;
            if (fontGlyphRun == null)
            {
                throw new ArgumentException(SR.Format(SR.MustBeOfType, "value", "GlyphRun"));
            }

            //
            // Obtain the font serialization service from the serlialization manager.
            //
            IServiceProvider resourceServiceProvider = manager.ResourcePolicy;
            XpsFontSerializationService fontService = (XpsFontSerializationService)resourceServiceProvider.GetService(typeof(XpsFontSerializationService));
            if (fontService == null)
            {
                throw new XpsSerializationException(SR.ReachSerialization_NoFontService);
            }

            //
            // Retrieve the current font subsetter
            //
            XpsFontSubsetter fontSubsetter = fontService.FontSubsetter;

            //
            // Add the font subset to the font subsetter and retrieve a Uri
            // to the font within the Xps package.
            //
            Uri resourceUri = fontSubsetter.ComputeFontSubset(fontGlyphRun);

            Toolbox.EmitEvent(EventTrace.Event.WClientDRXConvertFontEnd);

            return resourceUri;
        }

View on GitHub (pinned to 81131a70a4)