dotnet/wpf · error · XamlObjectReaderException

SR.DeferringLoaderInstanceNull

Error message

SR.DeferringLoaderInstanceNull

What it means

When a property must be saved with deferred content (x:XData, templates, etc.), XamlObjectReader looks up the XamlDeferringLoader configured for the property's type. The converter record exists but its ConverterInstance is null — the deferring loader could not be instantiated — so reading cannot defer the content and throws XamlObjectReaderException.

Solutions

  1. Ensure the XamlDeferringLoader type used by the property (via XamlDeferLoadAttribute or schema context lookup) has an accessible parameterless constructor and its assembly is loadable.
  2. Check the deferring loader's ConverterInstance before reading: if it is null, register a working loader or remove the defer-load requirement.
  3. Verify the schema context is configured with the correct assembly set so the loader type resolves.

Example fix

// before
[XamlDeferLoad(typeof(MyDeferringLoader), typeof(ContentElement))] // MyDeferringLoader has no parameterless ctor
public object Content { get; set; }
// after
public class MyDeferringLoader : XamlDeferringLoader
{
    public MyDeferringLoader() { } // ensure public parameterless ctor
    ...
}
Defensive patterns

Strategy: validation

Validate before calling

var loader = deferringLoader?.ConverterInstance;
if (loader is null) throw new InvalidOperationException($"Deferring loader {deferringLoader} could not be instantiated.");

Type guard

bool HasInstantiableLoader(XamlValueConverter<XamlDeferringLoader> c) => c?.ConverterInstance is not null;

Try / catch

try { return MemberMarkupInfo.ConvertToXamlReader(value, loader, context); }
catch (XamlObjectReaderException ex) when (ex.Message.Contains("deferring")) { /* fall back to non-deferred serialization or re-register loader */ }

Prevention

When it happens

Trigger: Reading an object whose property has a XamlValueConverter<XamlDeferringLoader> whose ConverterInstance is null (deferring loader type failed to construct or was registered with a null instance), reached via GetPropertyValueInfoInternal → ConvertToXamlReader (XamlObjectReader.cs:341-344).

Common situations: Custom XamlDeferringLoader implementations with no public parameterless constructor; a broken/misconfigured XamlSchemaContext that creates converter records lazily; type-level XamlDeferLoadAttribute pointing at an unavailable assembly.

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/cf1b9e4861b8200b. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlObjectReader.cs:344

                foreach (var ov in Children)
                {
                    ov.FindNamespace(context);
                }
            }

            private bool MemberRequiresNamespaceHoisting(XamlMember member)
            {
                return (member.IsAttachable || (member.IsDirective && !XamlXmlWriter.IsImplicit(member)))
                    && (member.PreferredXamlNamespace != XamlLanguage.Xml1998Namespace);
            }

            public static XamlTemplateMarkupInfo ConvertToXamlReader(
                object propertyValue, XamlValueConverter<XamlDeferringLoader> deferringLoader, SerializerContext context)
            {
                XamlDeferringLoader converter = deferringLoader.ConverterInstance;
                if (converter is null)
                {
                    throw new XamlObjectReaderException(SR.Format(SR.DeferringLoaderInstanceNull, deferringLoader));
                }

                context.Instance = propertyValue;
                XamlReader reader = context.Runtime.DeferredSave(context.TypeDescriptorContext, deferringLoader, propertyValue);
                context.Instance = null;
                using (reader)
                {
                    return new XamlTemplateMarkupInfo(reader, context);
                }
            }

            public static MemberMarkupInfo ForAttachedProperty
                (object source, XamlMember attachedProperty, object value, SerializerContext context)
            {
                if (GetSerializationVisibility(attachedProperty) == DesignerSerializationVisibility.Hidden)
                {
                    return null;
                }

View on GitHub (pinned to 81131a70a4)