dotnet/wpf · error · XamlObjectWriterException

Cannot get a XamlDeferringLoader from XamlValueConverter

Error message

Cannot get a XamlDeferringLoader from XamlValueConverter '{0}' because its ConverterInstance property is null.

What it means

ClrObjectRuntime.DeferredLoad resolves the XamlDeferringLoader for deferred (x:XData-like) content via GetConverterInstance(deferringLoader). If the XamlValueConverter has no ConverterInstance (the loader type could not be constructed/instantiated), it throws XamlObjectWriterException with DeferringLoaderInstanceNull. The library throws this because it cannot load deferred content without a live loader instance.

Solutions

  1. Ensure the deferring loader type has a public parameterless constructor and is instantiable (not abstract/generic-open)
  2. Add a reference to the assembly containing the XamlDeferringLoader type
  3. Verify the x:XamlDeferringLoader / XamlDeferringLoader attribute names the correct, existing type

Example fix

// before
class MyLoader<T> : XamlDeferringLoader { ... } // open generic, cannot construct
// after
class MyLoader : XamlDeferringLoader { public MyLoader() { } ... }
Defensive patterns

Strategy: try-catch

Validate before calling

var conv = schemaContext.GetXamlType(typeof(MyDeferredType)).DeferringLoader; bool ok = conv?.ConverterInstance != null; if (!ok) throw new InvalidOperationException("Deferring loader not instantiable for " + typeof(MyDeferredType));

Type guard

static bool HasLiveLoader(XamlValueConverter c) => c?.ConverterInstance != null;

Try / catch

try { LoadDeferred(content); } catch (XamlObjectWriterException ex) when (ex.Message.Contains("DeferringLoader")) { throw new InvalidOperationException("Check XamlDeferringLoader type: public parameterless ctor + referenced assembly", ex); }

Prevention

When it happens

Trigger: Calling DeferredLoad during XamlObjectWriter/ClrObjectRuntime processing of deferred content where the XamlDeferringLoader's XamlValueConverter.ConverterInstance is null — typically because the loader type failed to construct (no parameterless ctor, abstract type, missing assembly, type load failure).

Common situations: Custom XamlDeferringLoader with no public parameterless constructor; assembly containing the loader not referenced/available at load time; x:XamlDeferringLoader attribute pointing at a wrong or renamed type after a refactor.

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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Runtime/ClrObjectRuntime.cs:589

                throw CreateException(SR.Format(SR.SetXmlInstance, property), e);
            }
        }

        public override TConverterBase GetConverterInstance<TConverterBase>(XamlValueConverter<TConverterBase> converter)
        {
            return converter.ConverterInstance;
        }

        public override object DeferredLoad(ServiceProviderContext serviceContext,
                                             XamlValueConverter<XamlDeferringLoader> deferringLoader,
                                             XamlReader deferredContent)
        {
            try
            {
                XamlDeferringLoader converter = GetConverterInstance(deferringLoader);
                if (converter is null)
                {
                    throw new XamlObjectWriterException(SR.Format(SR.DeferringLoaderInstanceNull, deferringLoader));
                }

                return converter.Load(deferredContent, serviceContext);
            }
            catch (Exception e)
            {
                // Reset the reader in case our caller catches and retries
                if (deferredContent is IXamlIndexingReader indexingReader && indexingReader.CurrentIndex >= 0)
                {
                    indexingReader.CurrentIndex = -1;
                }

                if (CriticalExceptions.IsCriticalException(e) || e is XamlException)
                {
                    throw;
                }

                throw CreateException(SR.DeferredLoad, e);

View on GitHub (pinned to 81131a70a4)