I am using a PivotViewer and seeing this exception being thrown from iexplorer.exe.
"Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.ArgumentException: ICollectionView can only contain items that are in the PivotViewer's ItemsSource
at Microsoft.Internal.Pivot.ViewModels.GridViewModel.UpdateOnModelChanged()
at Microsoft.Internal.Pivot.ViewModels.ViewBaseViewModel.OnUpdateComplete(Object sender, EventArgs e)
at System.Windows.Controls.Pivot.PivotViewerView.ExposeCollectionView(ICollectionView collectionView, CollectionViewSource collectionSource, IDisposable deferrer)
at System.Windows.Controls.Pivot.PivotViewerView.SetModel(PivotViewerProperty sortPivotProperty, IEnumerable`1 source)
at Microsoft.Internal.Pivot.Controls.CollectionViewContainer.UpdateContent()
at Microsoft.Internal.Pivot.Controls.CollectionViewContainer.b__0()
"
Here is a description of what I am doing. The pivot viewer's ItemsSource is bound to an ObservableCollection called "Sessions" in the ViewModel. When the user hit my website the first time, he's not logged in and I will populate the pivot viewer from a remote demo database (by using WebClient.OpenReadAsync). When the user logs in, I will clear "Sessions" and read the data asynscrhonizely from his own database (using the same code WebClient.OpenReadAsync). Everything works as expected at this point. The PivotViewer shows the demo data and refreshs fine after he logged in.
The problem occurs when he logged out, when I use the same code to clear "Sessions" and read the data asynchonizedly again from the demo database. It throws the above exception.
I have a workaround. When the user logs out, if I still clear "Sessions" but don't add any data from the demo database, it will work. I am able to log in and log out multiple times without any problem. So this shows the problem probably is related to the code where I add data to "Session" ObservableCollection.
I am also guessing it's a race condition related to threading caused by WebClient's OpenReadAsync to read data from a remote website.
I am stuck now and any help would be appreciated. Thanks!