System.ArgumentException An item with the same key has already been added. Key: Item

I have a SFDataGrid which ItemSource is an observable Collection of observable objects .
In order to construct the columns i enumerate the proerties of my object and add them as you see below. I have a Property which type is of ESFIItem . if i uncomment this line an unhandled exception occurs 

App_UnhandledException D:\Development\EntersoftUniversal - SFGrid\UWP\App.xaml.cs:34  System.ArgumentException  An item with the same key has already been added. Key: Item    ParamName=null    Data=...    InnerException={ }    
   at Xamarin.Forms.Platform.UWP.TaskExtensions.<>c.<WatchForError>b__2_1(Object e)
   at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()    HelpLink=null    Source=Xamarin.Forms.Platform.UAP    HResult=-2147024809


MoreOver i see that the GUID columns are not getting filled with data



foreach (PropertyInfo propertyInfo in typeof(ESTMTaskItem).GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase))
                {
                    var targetType = propertyInfo.PropertyType.IsNullableType()
                        ? Nullable.GetUnderlyingType(propertyInfo.PropertyType)
                        : propertyInfo.PropertyType;

                    if ((
                        targetType == typeof(DateTime) || 
                        targetType == typeof(DateTime?)  
                        || targetType == typeof(Decimal)
                         || targetType == typeof(String)
                         || targetType == typeof(Byte)
                         || targetType == typeof(Guid?)
                         || targetType == typeof(Guid)
                        ))
                    {

                        ESDebug.Log("*********" + propertyInfo.Name + "*********");
                        this._DataGrid.Columns.Add(new GridTextColumn()
                        {
                            MappingName = propertyInfo.Name,
                            HeaderText = propertyInfo.Name,
                            HeaderCellTextSize = 20,
                            HeaderFontAttribute = FontAttributes.Bold,
                            HeaderTextAlignment = TextAlignment.Start,
                            LineBreakMode = LineBreakMode.TailTruncation

                        });
                    }
                }

Attachment: EntersoftUniversal__SFGrid__ForDeploy_bbb8b32a.rar

1 Reply

AN Ashok N Syncfusion Team October 25, 2017 01:04 PM UTC

Hi Loukas, 
 
Thanks for contacting Syncfusion support. 
 
We have checked your application and you are using property name is Item in ESTMTaskItem class(EntersoftUniversal\Shared\EntityObjects\ESTM), also you are using indexer property in the name of this in EntityObject class(EntersoftUniversal\Shared\DataLayer). Xamarin.Forms Indexer property default key name is Item and you also using same name in your application so application has been crashed due to two different values with same key name. We request you to rename your Item property based on your requirement. We have modified the application by changing the Item property name as ESFIItem and attached in the below location, please check it. 
 
 
Regards, 
Ashok 


Loader.
Up arrow icon