dotnet/wpf · error · InvalidOperationException

SR.MissingValueConverter

Error message

SR.MissingValueConverter

What it means

When UseDefaultValueConverter is false, BindingExpression expects the binding's Converter to be supplied explicitly; AttachToContext throws this InvalidOperationException if Converter is null. The code comment 'report instead of throw?' indicates this is an engine-internal invariant: without either the default converter machinery or an explicit converter, values cannot be transferred.

Solutions

  1. Set Converter on the Binding (an IValueConverter implementation) when UseDefaultValueConverter is false
  2. Enable UseDefaultValueConverter (or leave default) so the engine supplies DefaultValueConverter
  3. If writing custom expression internals, ensure Converter is assigned before AttachToContext runs

Example fix

// before
binding.Converter = null; // with UseDefaultValueConverter=false -> throws MissingValueConverter
// after
binding.Converter = new MyValueConverter();
Defensive patterns

Strategy: validation

Validate before calling

if (!binding.UseDefaultValueConverter && binding.Converter == null) binding.Converter = myConverter; // assign before attach

Type guard

static bool ConverterReady(Binding b) => b.UseDefaultValueConverter || b.Converter != null;

Try / catch

try { /* attach expression */ } catch (InvalidOperationException ex) when (ex.Message.Contains("converter")) { binding.Converter = new DefaultConverter(); /* retry attach */ }

Prevention

When it happens

Trigger: Creating a custom BindingExpressionBase-derived scenario or using internal APIs with UseDefaultValueConverter=false while leaving ParentBinding.Converter null — typically in custom expression subclasses, mock/fake binding setups, or advanced internal-framework code.

Common situations: Rare in app code; encountered by library authors extending WPF binding internals, unit-test harnesses building partial binding expressions, or framework customizations that disable the default converter pipeline.

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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpression.cs:825

                // of an element with no parent.  Just use null.
                source = null;
            }

            // if we get this far, all the ingredients for a successful binding
            // are present.  Remember what we've found and activate the binding.
            if (contextElement != null)
                _ctxElement = new WeakReference(contextElement);

            // attach to context element
            ChangeWorkerSources(null, 0);

            if (!UseDefaultValueConverter)
            {
                Converter = ParentBinding.Converter;

                if (Converter == null)
                {
                    throw new InvalidOperationException(SR.MissingValueConverter); // report instead of throw?
                }
            }

            // join the right binding group (if any)
            JoinBindingGroup(IsReflective, contextElement);

            SetStatus(BindingStatusInternal.Inactive);

            // inner BindingExpressions of PriorityBindingExpressions may not need to be activated
            if (IsInPriorityBindingExpression)
                ParentPriorityBindingExpression.InvalidateChild(this);
            else    // singular BindingExpressions and those in MultiBindingExpressions should always activate
                Activate(source);

            GC.KeepAlive(target);   // keep target alive during activation (bug 956831)
        }

        // Detach from things that may require tree context

View on GitHub (pinned to 81131a70a4)