BindableCollection<T>.AddRange implementation error

Topics: Bugs
Jan 10, 2013 at 9:39 AM

INPC.cs line 463, as of commit b70a5350a693

The implemented change in this commit causes a NotSupportedException «range actions are not supported», when executing OnCollectionChanged on line 477. The same problem occurs with RemoveRange (line 488) when executing OnCollectionChanged on line 503.

Jan 10, 2013 at 11:12 AM

On what platform (WP8, WPF or WinRT) do you have this issue?

Jan 10, 2013 at 11:14 AM
tibel wrote:

On what platform (WP8, WPF or WinRT) do you have this issue?

WPF

Jan 10, 2013 at 11:27 AM
Edited Jan 10, 2013 at 11:28 AM

 

var col = new BindableCollection<int>();
col.AddRange(new int[] {1,2,3});

 

This is working for me on .NET 4.0 and .NET 4.5
So maybe you throw this exception in your event handler attached to "CollectionChanged" event?

Jan 10, 2013 at 11:41 AM

My code is almost alike, but sends in an IList<T> as parameter (UnitCollection is a BindableCollection<Unit>):

var list = Units.Where(t => t.Primary).ToList();

UnitCollection.Clear()
UnitCollection.AddRange(list);

The UnitCollection is set as ItemSource for a ListView in the GUI (xaml). The NotSupportedException is thrown by the System.Windows.Data.ListCollectionView when method «ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)» calls «this.ValidateCollectionChangedEventArgs(args)»

protected override void ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
{
	if (args == null)
	{
		throw new ArgumentNullException("args");
	}
	this.ValidateCollectionChangedEventArgs(args);
	...

and 

private void ValidateCollectionChangedEventArgs(NotifyCollectionChangedEventArgs e)
{
	switch (e.Action)
	{
	case NotifyCollectionChangedAction.Add:
		if (e.NewItems.Count != 1)
		{
			throw new NotSupportedException(SR.Get("RangeActionsNotSupported"));
		}
		break;
		...

Jan 10, 2013 at 11:44 AM

Already found this article, describing the issue.
Thanks for finding the issue I will fix that.

Jan 10, 2013 at 11:51 AM

Thanks in advance!