{"record":{"id":"2e3e0ca206af96e7","repo":"dotnet/wpf","slug":"sr-format-sr-bindingcollectioncontainsnonbinding-binding","errorCode":null,"errorMessage":"SR.Format(SR.BindingCollectionContainsNonBinding, binding.GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.BindingCollectionContainsNonBinding, binding\\.GetType\\(\\)\\.Name\\)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/BindingCollection.cs","lineNumber":114,"sourceCode":"\n            base.SetItem(index, item);\n            OnBindingCollectionChanged();\n        }\n\n        #endregion Protected Methods\n\n\n        //------------------------------------------------------\n        //\n        //  Private Methods\n        //\n        //------------------------------------------------------\n\n        private void ValidateItem(BindingBase binding)\n        {\n            // for V1, we only allow Binding as an item of BindingCollection.\n            if (!(binding is Binding))\n                throw new NotSupportedException(SR.Format(SR.BindingCollectionContainsNonBinding, binding.GetType().Name));\n        }\n\n        private void OnBindingCollectionChanged()\n        {\n            if (_collectionChangedCallback != null)\n                _collectionChangedCallback();\n        }\n\n        //------------------------------------------------------\n        //\n        //  Private Fields\n        //\n        //------------------------------------------------------\n\n        private BindingBase _owner;\n        private BindingCollectionChangedCallback _collectionChangedCallback;\n    }\n","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Data/BindingCollection.cs#L96-L132","documentation":"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.","triggerScenarios":"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.","commonSituations":"Adding MultiBinding to a collection typed/behaving as BindingCollection; reflection-based or serializer-driven population of bindings; older code paths predating BindingBase collections.","solutions":["Only add plain Binding instances to this collection","Use a BindingBase-compatible collection (e.g. the one on DependencyObject via SetBinding, or Setter/Trigger collections) for MultiBinding/PriorityBinding","Unwrap the MultiBinding into individual Bindings where the API permits only Binding"],"exampleFix":"// before\nbindings.Add(new MultiBinding());\n// after\nbindings.Add(new Binding(\"Path\") { Source = source });","handlingStrategy":"type-guard","validationCode":"if (binding is not Binding) throw new NotSupportedException(\"BindingCollection accepts only Binding instances\");","typeGuard":"bool IsPlainBinding(BindingBase b) => b is Binding;","tryCatchPattern":"try { collection.Add(binding); } catch (NotSupportedException) { /* use a BindingBase-capable collection instead */ }","preventionTips":["Only add Binding, not MultiBinding/PriorityBinding, to BindingCollection","Use SetBinding on the DependencyObject for complex bindings","Review reflection/serialization code paths that populate binding collections"],"tags":["wpf","databinding","not-supported"],"backgroundTag":"type-mismatch","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}