Fix Window Phone LongListSelector dynamic binding exception

Sometime, you are receive an exception error when using Window Phone Toolkit LongListSelector control. It occur while you are trying to modify ItemsSource which is ObservableCollection (or any implement INotifyCollectionChanged interface) of the LongListSelector control.

The error message can form: ArgumentOutOfRangeException is being thrown within InsertNewGroups in LongListSelector.cs
And the part of stack trace could be:

at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource
at System.Collections.ObjectModel.Collection`1.Insert(Int32 index, LongListSelectorItem item)
at Microsoft.Phone.Controls.LongListSelector.InsertNewGroups(IList newGroups, Int32 newGroupsIndex)
at Microsoft.Phone.Controls.LongListSelector.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, Group`1 item)
at System.Collections.ObjectModel.Collection`1.Add(Group`1 item)

It seem like a bug of the Toolkit. Luckily, this bug is now fixed by the author and we need not do more. Unfortunately, somehow the fixing is not implement in current version of Window Phone Toolkit (Nov 2011 or version 75588). So we need to download the source code of Toolkit at and then compile it to .dll library for using.

After compiled the source code you will get the file name Microsoft.Phone.Controls.Toolkit.dll. Just copy it to somewhere you like and replace the default Toolkit library (in .NET packed) of your Project's References to the new that you have compiled.

To learn how to add/remove referece in .NET project. You can try this link "Adding and Removing References"