dotnet/wpf · error · NotSupportedException

SR.Format(SR.BindingCollectionContainsNonBinding…

Error message

SR.Format(SR.BindingCollectionContainsNonBinding, binding.GetType().Name)

What it means

BindingCollection historically only accepts items of type Binding (not other BindingBase derivatives like MultiBinding or PriorityBinding). ValidateItem throws NotSupportedException when a non-Binding item is inserted or set.

Solutions

  1. Only add plain Binding instances to this collection
  2. Use a BindingBase-compatible collection (e.g. the one on DependencyObject via SetBinding, or Setter/Trigger collections) for MultiBinding/PriorityBinding
  3. Unwrap the MultiBinding into individual Bindings where the API permits only Binding

Example fix

// before
bindings.Add(new MultiBinding());
// after
bindings.Add(new Binding("Path") { Source = source });
Defensive patterns

Strategy: type-guard

Validate before calling

if (binding is not Binding) throw new NotSupportedException("BindingCollection accepts only Binding instances");

Type guard

bool IsPlainBinding(BindingBase b) => b is Binding;

Try / catch

try { collection.Add(binding); } catch (NotSupportedException) { /* use a BindingBase-capable collection instead */ }

Prevention

When it happens

Trigger: Calling BindingCollection.Add/Insert/SetItem (e.g. via BindingOperations.SetBinding with a collection, or adding to BindingGroup.Bindings-style collections) with a MultiBinding, PriorityBinding, or custom BindingBase.

Common situations: Adding MultiBinding to a collection typed/behaving as BindingCollection; reflection-based or serializer-driven population of bindings; older code paths predating BindingBase collections.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/2e3e0ca206af96e7. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/BindingCollection.cs:114

            base.SetItem(index, item);
            OnBindingCollectionChanged();
        }

        #endregion Protected Methods


        //------------------------------------------------------
        //
        //  Private Methods
        //
        //------------------------------------------------------

        private void ValidateItem(BindingBase binding)
        {
            // for V1, we only allow Binding as an item of BindingCollection.
            if (!(binding is Binding))
                throw new NotSupportedException(SR.Format(SR.BindingCollectionContainsNonBinding, binding.GetType().Name));
        }

        private void OnBindingCollectionChanged()
        {
            if (_collectionChangedCallback != null)
                _collectionChangedCallback();
        }

        //------------------------------------------------------
        //
        //  Private Fields
        //
        //------------------------------------------------------

        private BindingBase _owner;
        private BindingCollectionChangedCallback _collectionChangedCallback;
    }

View on GitHub (pinned to 81131a70a4)