dotnet/wpf · error · InvalidOperationException
SR.Format(SR.DeferringLoaderNoContext…
Error message
SR.Format(SR.DeferringLoaderNoContext, nameof(DeferrableContentConverter), typeof(T).Name)
What it means
DeferrableContentConverter's private RequireService<T> helper resolves a required service (IXamlSchemaContextProvider, IXamlObjectWriterFactory, IProvideValueTarget, IRootObjectProvider) from the ambient IServiceProvider. If GetService returns null for the requested type, it throws InvalidOperationException stating the deferring loader has no context, naming the missing service type.
Solutions
- Invoke the converter only within a real XAML parse (Baml2006Reader/XamlXmlReader + XamlObjectWriter), which supplies all required services
- In test harnesses, register all four services: IXamlSchemaContextProvider, IXamlObjectWriterFactory, IProvideValueTarget, IRootObjectProvider
- Read the exception message to see which typeof(T).Name is missing and add that service registration
Example fix
// before var provider = new ServiceProvider(); // no services registered converter.ConvertFrom(provider, CultureInfo.InvariantCulture, bamlStream); // after var sp = new ServiceProvider(); sp.AddService(typeof(IXamlSchemaContextProvider), schemaContextProvider); sp.AddService(typeof(IXamlObjectWriterFactory), writerFactory); sp.AddService(typeof(IProvideValueTarget), pvt); sp.AddService(typeof(IRootObjectProvider), rootProvider);
Defensive patterns
Strategy: validation
Validate before calling
static void RequireDeferrableServices(IServiceProvider p)
{
foreach (var t in new[] { typeof(IXamlSchemaContextProvider), typeof(IXamlObjectWriterFactory), typeof(IProvideValueTarget), typeof(IRootObjectProvider) })
if (p.GetService(t) == null) throw new InvalidOperationException($"Missing service: {t.Name}");
} Type guard
static bool HasRequiredXamlServices(IServiceProvider p) =>
p.GetService(typeof(IXamlSchemaContextProvider)) != null &&
p.GetService(typeof(IXamlObjectWriterFactory)) != null &&
p.GetService(typeof(IProvideValueTarget)) != null &&
p.GetService(typeof(IRootObjectProvider)) != null; Try / catch
try { return (DeferrableContent)converter.ConvertFrom(provider, culture, value); }
catch (InvalidOperationException ex) when (ex.Message.Contains("DeferrableContentConverter")) { /* log which service is missing from the message */ } Prevention
- Run DeferrableContentConverter only inside a real XAML reader/writer parse session
- In test stubs, register all four required services before calling ConvertFrom
- Read the exception message to identify exactly which service type was absent
When it happens
Trigger: Calling ConvertFrom with a service provider (ITypeDescriptorContext) that does not supply one of the required services — typically a hand-built ServiceProvider or a plain TypeDescriptor context with no XAML ambient services.
Common situations: Unit-testing the converter with a stub service provider that registers only some services, invoking the converter outside a XAML reader/writer session, or a custom XAML pipeline that omits IXamlObjectWriterFactory or IRootObjectProvider.
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
- NotImplementedException
- SR.Format(SR.DeferringLoaderNoContext…
- SR.Format(SR.MarkupExtensionNoContext, GetType().Name…
- SR.Format(SR.MarkupExtensionNoContext, GetType().Name…
- SR.MarkupExtensionNoContext
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/34e732b932730bb1.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DeferrableContentConverter.cs:80
{
throw new InvalidOperationException(SR.ExpectedBinaryContent);
}
// we shouldn't pass around the service provider
DeferrableContent deferrableContext = new DeferrableContent(stream, schemaContext,
objectWriterFactory, context, rootObjectProvider.RootObject);
return deferrableContext;
}
return base.ConvertFrom(context, culture, value);
}
private static T RequireService<T>(IServiceProvider provider) where T : class
{
T result = provider.GetService(typeof(T)) as T;
if (result == null)
{
throw new InvalidOperationException(SR.Format(SR.DeferringLoaderNoContext, nameof(DeferrableContentConverter), typeof(T).Name));
}
return result;
}
}
}
View on GitHub (pinned to 81131a70a4)