Hello
I keep getting this error "Item is already added to the collection!" when using the LoadCustomizations method of FlatDataSource.
When I check the rows there is no initial value, so could you please tell me what property I need to clear manually on the rows so that I get rid of all of the initial values?
Thank you
Hello Stergios,
Thank you for your post.
I have created a sample project based on the original description of this issue, but so far, I haven't been able to reproduce the issue you are seeing. I have attached the sample project I have used to test this. My tests were done using version 15.2.20152.2038 in Infragistics for WPF 2015 Volume 2. Does this version match the version you are currently using? If not, could you please provide the version that you are using so that I can test against that one as well?
If the attached sample project does show the product feature working correctly, this indicates a possible problem in the code of your application. This leads me to be suspicious about whether something is happening in your application that may cause this issue to occur. For example, are you adding any Rows, Columns, Measures, or Filters to your FlatDataSource programmatically before or after loading the customizations of that data source? Also, would it be possible for you to please provide some more detail as to the way you are saving the data source's customizations? For example, are you saving to a string or a stream? Furthermore, could you please provide some detail as to when the customizations are being saved and loaded as well?
Or, if this sample project is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.
Please let me know if I may be of any further assistance on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Hello Andrew
Thank you for your reply.
I am using version 15.2.20152.1000.
I have tried your sample application and I can say that it works just because the functionality is the bare minimum.
I am saving my ustomizations to a string.
In my application I execute load customizations and then, since there is no event for data loaded, I try to add a row programmatically. The problem is that the LoadCustomizations does not have an immediate effect so the FlatDataSource.Rows doesn't have any info of what is to be loaded. Subsequently I don't know which field to check so that I don't load the same dimension twice. And then as the pivot grid renders I get the "Item already added to the collection" exception which comes from the control. I think that your pivot grid control could use a guard and not throw this exception.
So all I am asking is what field should I check after the LoadCustomizations has been executed so that I don't try to add an already existing dimension.
I think it is pretty straight forward what I am trying to accomplish so I won't include a project.
If you need any more details please let me know.
Thanks
Stergios
Thank you for the details regarding what is happening in your application.
I have been looking into this issue a bit further, and currently the reason why there isn't an event that fires when the LoadCustomizations method completes is because these customizations are loaded asynchronously. One thing you could possibly do here is parse the customizations string that you are saving to check if the row you are looking to programmatically add already exists in that collection. If it does, then you should defer from adding that particular row, or you will likely cause this exception to fire.
Another route that you could possibly take is to handle the ResultChanged event of your data source. The LoadCustomizations completing will cause this ResultChanged event to fire, and then you can look through the Rows, Columns, and Filters collection to be sure that the member that you are looking to add to the Rows collection doesn't exist there. The elements that exist in these Rows, Columns, and Filters collections are of the type FlatDataFilterViewModel and each of these elements have a Caption property that you can check to see if it corresponds to the Row that you are looking to add.
There is a third possibility here as well. I am curious if this exception that you are seeing happens without the programmatic addition of a Row to your XamPivotGrid's data source. The reason that I wonder about this is because it has come to my attention that we have logged a development issue internally for an exception occurring with the XamPivotGrid in the 15.2 version when loading customizations to the XamPivotGrid's data source. I would like you to take a look at the text file I have attached. Inside is the stack trace of the exception that is related to this internally logged bug. Does this stack trace look similar to the one you are currently seeing?
Please let me know if you have any other questions or concerns on this matter.
Hello Andrew,
Thank you for your reply and suggestions.
Your first solution is what I have already implemented. I was just wondering if there was a cleaner approach.
About your second suggestion, the ResultChanged event gets fired multiple times and the rows, columns, filters are not always populated so it's not a good idea to rely on this event.
I have checked my logs for the exception stack trace and below are three cases that I found. I can say that I have seen this exception too many times when messing with the customizations, and I would really appreciate it if a fix for this is included in a coming release.
System.ArgumentException: Item is already added to the collection! at Infragistics.Olap.AreaItemsCollection.OnCollectionChanging(NotifyCollectionChangedEventArgs e) at Infragistics.Olap.SwapCollection`1.InsertItemInternal(Int32 index, T item, Boolean suppressMessages) at Infragistics.Olap.DataSourceSnapshot.AddViewModelsToDataSource() at Infragistics.Olap.DataSourceSnapshot.<>c__DisplayClass1d.<ProcessFilterViewModelMembers>b__1c(Object ac) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) System.ArgumentException: Item is already added to the collection! at Infragistics.Olap.AreaItemsCollection.OnCollectionChanging(NotifyCollectionChangedEventArgs e) at Infragistics.Olap.SwapCollection`1.InsertItemInternal(Int32 index, T item, Boolean suppressMessages) at Infragistics.Olap.SwapCollection`1.InsertItem(Int32 index, T item) at Infragistics.Olap.AreaItemsCollection.InsertItem(Int32 index, IAreaItemViewModel item) at Infragistics.Olap.DataSourceSnapshot.AddViewModelsToDataSource() at Infragistics.Olap.DataSourceSnapshot.<>c__DisplayClass1d.<ProcessFilterViewModelMembers>b__1c(Object ac) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) System.ArgumentException: Item is already added to the collection! at Infragistics.Olap.AreaItemsCollection.OnCollectionChanging(NotifyCollectionChangedEventArgs e) at Infragistics.Olap.SwapCollection`1.InsertItemInternal(Int32 index, T item, Boolean suppressMessages) at Infragistics.Olap.FlatData.FlatDataSource.UpdateHierarchiesCollection(AreaItemsCollection hierarchiesCollection) at Infragistics.Olap.DataSourceBase.LoadInitialAreaItems() at Infragistics.Olap.DataSourceBase.CompositionTarget_Rendering(Object sender, EventArgs e) at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget) at System.Windows.Media.MediaContext.AnimatedRenderMessageHandler(Object resizedCompositionTarget) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
It does seem that the issue you are seeing was best described as the third option in my previous response to this post. The stack traces that you have provided look very similar to the one in the internally logged development issue with the XamPivotGrid's LoadCustomizations, and the steps you are currently taking seem to be similar to the reproduction steps for this bug as well.
I have made a support case viewable to you so that I can link this development issue to it in order for you to be able to follow its progress. This support case has an ID of CAS-170669-X7S9G9, and I will be linking a development issue with ID 212766 to it so that you can be notified when a fix becomes available. You can access and send updates to this private support case after signing into your account at: https://www.infragistics.com/my-account/support-activity. The next step will be for a XamPivotGrid developer to make a fix or other resolution to this development issue - at which time you will be notified via the support case.