Uploaded image for project: 'Realm .NET SDK'
  1. Realm .NET SDK
  2. RNET-624

[Bug]: NotifyCollectionChangedEventArgs OldItem is InvalidObject when updating the data

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      What happened?

      We are using Realms object and in Syncfusion ListView. We have a realm query that is bound to the ItemsSource of the list like below,

                  var realm = Realm.GetInstance();
                  
                  //just clean everything
                  realm.Write(() => realm.RemoveAll());
      
                  realm.Write(() =>
                  {
                      for (int i = 0; i < 10; i++)
                      {
                          realm.Add(new ItemModel()
                          {
                              Title = i.ToString(),
                              Subtitle = Guid.NewGuid().ToString("N").Substring(0, 5),
                              IsDirectory = false
                          });
                      }
                  });
      
                  var query = realm.All<ItemModel>().Where(im => im.IsDirectory == true);
                  listview.ItemsSource = query;
      

      The list will have the items with IsDirectory is true. When updating the IsDirectory to false, the item is removed from the query and the CollectionChanged event is fired with Remove action.

      The problem we are facing is, in the NotifyCollectionChangedEventArgs, the olditem is InvalidObject.

      Due to this, we could not get the proper item in the syncfusion level to update the SfListView. Since the removed item is invalidobject, we could not get the proper index/item to remove it from our end.

      Note: The issue occurs from version 10.4.0. Before this version, the OldItem is null.

      We need the e.OldItems as actual data or null to process in the syncfusion source level.

      Repro steps

      1. Run the attached sample (ReplicationSample)
      2. Click update
      3. The IsDirectory property is updated, and the CollectionChanged event will be triggered. But, the OldItem is invalidobject.

      Version

      10.7.0

      What SDK flavour are you using?

      Local Database only

      What type of application is this?

      Xamarin

      Client OS and version

      10.7.0

      Code snippets

          private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
          {
              Debug.WriteLine($"<||> OnCollectionChanged. {e.Action}, {e.NewItems?.Count}, {e.OldItems?.Count}");
      
              if (e.Action == NotifyCollectionChangedAction.Remove)
              {
                  var oldItem = e.OldItems[0];
                  if (oldItem == null)
                  {
                      //The olditem is null till v10.3.0
                      Debug.WriteLine("OldItem is: " + oldItem);
                  }
                  else
                  {
                      //Invalidate object passed as olditem from v10.4.0
                      Debug.WriteLine("OldItem is: " + oldItem);
                  }
              }
          }
      

      Stacktrace of the exception/crash you're getting

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      NA
      

      Relevant log output

      Unable to find source-code formatter for language: shell. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      NA
      

            Assignee:
            ferdinando.papale@mongodb.com Ferdinando Papale
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: