dotnet/wpf · error · InvalidOperationException
SR.MissingNameProvider
Error message
SR.MissingNameProvider
What it means
NameReferenceConverter.ConvertTo throws InvalidOperationException (SR.MissingNameProvider) when the context's GetService(typeof(IXamlNameProvider)) returns null. Serializing an object back to its XAML name requires an IXamlNameProvider service; without it the converter cannot produce a name string. This mirrors the ConvertFrom MissingNameResolver error on the serialization side.
Solutions
- Invoke ConvertTo within a XAML serialization pipeline (XamlObjectWriter/XamlXmlWriter ecosystem) that provides IXamlNameProvider.
- In custom hosts, implement and register IXamlNameProvider on the service provider backing the context.
- Check for the service's availability before calling ConvertTo and choose a fallback serialization strategy otherwise.
Example fix
// before converter.ConvertTo(new PlainContext(), culture, obj, typeof(string)); // no IXamlNameProvider // after var ctx = new XamlSerializationContext(serviceProviderWithNameProvider); var name = (string)converter.ConvertTo(ctx, culture, obj, typeof(string));
Defensive patterns
Strategy: type-guard
Validate before calling
var nameProvider = context?.GetService(typeof(IXamlNameProvider));
if (nameProvider is null) throw new InvalidOperationException("IXamlNameProvider service unavailable; cannot serialize name"); Type guard
bool CanConvertToName(ITypeDescriptorContext ctx) => ctx?.GetService(typeof(IXamlNameProvider)) is IXamlNameProvider;
Try / catch
try { var name = (string)converter.ConvertTo(context, culture, obj, typeof(string)); }
catch (InvalidOperationException ex) when (ex.Message == SR.MissingNameProvider) { /* use fallback serialization */ } Prevention
- Run ConvertTo only inside a XAML save pipeline that establishes IXamlNameProvider.
- Register IXamlNameProvider in custom serializer hosts and designers.
- Verify service availability in an integration test for your serialization path.
When it happens
Trigger: Calling ConvertTo with an ITypeDescriptorContext whose GetService(typeof(IXamlNameProvider)) returns null — e.g. serializing outside a XAML save pipeline or with a stub context.
Common situations: Custom XAML serializers or designer export paths that forget to supply IXamlNameProvider; unit tests exercising ConvertTo with minimal contexts; serialization invoked before the name scope has been established.
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
- SR.Format(SR.MarkupExtensionNoContext, GetType().Name…
- SR.MissingNameResolver
- SR.MissingNameResolver
- ArgumentNullException(nameof(writer))
- InvalidOperationException(SR.Format(SR.XamlTypeNameCannotGet…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/e5ab04cf30d71a97.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Windows/Markup/NameReferenceConverter.cs:72
return false;
}
if (destinationType == typeof(string))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
ArgumentNullException.ThrowIfNull(context);
var nameProvider = (IXamlNameProvider)context.GetService(typeof(IXamlNameProvider));
if (nameProvider is null)
{
throw new InvalidOperationException(SR.MissingNameProvider);
}
return nameProvider.GetName(value);
}
}
}
View on GitHub (pinned to 81131a70a4)