Description
PriorityBinding.InitializeClone has the same off-by-one bug that was fixed for MultiBinding in #3220 / #3221.
The fix for MultiBinding changed i<=_bindingCollection.Count to i<_bindingCollection.Count, but the identical bug in PriorityBinding was not addressed.
https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/PriorityBinding.cs#L116
Reproduction Steps
var priorityBinding = new PriorityBinding();
priorityBinding.Bindings.Add(new Binding("Path1"));
priorityBinding.Bindings.Add(new Binding("Path2"));
var cloneMethod = typeof(BindingBase).GetMethod("Clone", BindingFlags.Instance | BindingFlags.NonPublic);
var clone = cloneMethod.Invoke(priorityBinding, new object[] { BindingMode.Default }); // throws ArgumentOutOfRangeException
Expected behavior
PriorityBinding should be cloned without exception
Actual behavior
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Collections.Generic.List`1.get_Item(Int32 index)
at System.Windows.Data.PriorityBinding.InitializeClone(BindingBase baseClone, BindingMode mode)
at System.Windows.Data.BindingBase.Clone(BindingMode mode)
Regression?
No. This bug has existed since the code was written. The same bug in MultiBinding was fixed in #3221, but PriorityBinding was not included in that fix
Known Workarounds
Clone PriorityBinding manually by creating a new instance and copying properties/bindings
Impact
No response
Configuration
- .NET 10.0 (also reproduces on .NET Framework 4.8)
- Windows 11
- x64
- Not specific to configuration
Other information
No response
Description
PriorityBinding.InitializeClonehas the same off-by-one bug that was fixed forMultiBindingin #3220 / #3221.The fix for
MultiBindingchangedi<=_bindingCollection.Counttoi<_bindingCollection.Count, but the identical bug inPriorityBindingwas not addressed.https://github.com/dotnet/wpf/blob/main/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/PriorityBinding.cs#L116
Reproduction Steps
Expected behavior
PriorityBindingshould be cloned without exceptionActual behavior
Regression?
No. This bug has existed since the code was written. The same bug in
MultiBindingwas fixed in #3221, butPriorityBindingwas not included in that fixKnown Workarounds
Clone
PriorityBindingmanually by creating a new instance and copying properties/bindingsImpact
No response
Configuration
Other information
No response