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

INotifyCollectionChanged implementation not compatible with ListCollectionView in WPF

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None

      What happened?

      I'm evaluating Realm and how we'd go about replacing SQLite as a database in our WPF application.

      One thing that I've encountered is that the INotifyCollectionChanged implementation can lead to issues when bound to a control that uses ListCollectionView, such as ListView.

      Since ListCollectionView does not support range actions, it's very easy to trigger: add or remove two adjacent objects in a single transaction and you'll get a NotSupportedException saying "Range actions are not supported.".

      ListCollectionView throws the exception whenever it detects range actions for:

      • NotifyCollectionChangedAction.Add
      • NotifyCollectionChangedAction.Remove
      • NotifyCollectionChangedAction.Replace
      • NotifyCollectionChangedAction.Move

      Repro steps

      • Bind an IQueryable<T> to ListView.
      • In one transaction, either add or remove two adjacent objects.
        • Whether this is done on a thread-pool thread or on the UI thread does not matter.
      • ListCollectionView throws an exception with a message saying "Range actions are not supported."

      Version

      11.6.1

      What Atlas Services are you using?

      Local Database only

      What type of application is this?

      WPF

      Client OS and version

      Windows 11 23H2 22631.2792

      Code snippets

      No response

      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
      System.NotSupportedException: Range actions are not supported.
         at System.Windows.Data.ListCollectionView.ValidateCollectionChangedEventArgs(NotifyCollectionChangedEventArgs e)
         at System.Windows.Data.ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
         at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
         at Realms.RealmCollectionBase`1.OnChange(IRealmCollection`1 sender, ChangeSet change)
         at Realms.NotificationCallbacks`1.Notify(ChangeSet changes, Boolean shallow)
         at Realms.RealmCollectionBase`1.Realms.INotifiable<Realms.NotifiableObjectHandleBase.CollectionChangeSet>.NotifyCallbacks(Nullable`1 changes, Boolean shallow)
         at Realms.NotifiableObjectHandleBase.NotifyObjectChanged(IntPtr managedHandle, CollectionChangeSet* changes, Boolean shallow)
         at Realms.SynchronizationContextScheduler.scheduler_invoke_function(IntPtr function_ptr, Boolean can_execute)
         at Realms.SynchronizationContextScheduler.Scheduler.<Post>b__5_0(Object f_ptr)
         at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
         at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
         at System.Windows.Threading.DispatcherOperation.InvokeImpl()
         at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
         at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
      --- End of stack trace from previous location ---
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Windows.Threading.DispatcherOperation.Invoke()
         at System.Windows.Threading.Dispatcher.ProcessQueue()
         at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
         at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
         at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
         at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
         at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
         at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
         at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
         at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
         at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
         at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
         at System.Windows.Threading.Dispatcher.Run()
         at System.Windows.Application.RunDispatcher(Object ignore)
         at System.Windows.Application.RunInternal(Window window)
         at System.Windows.Application.Run()
         at RealmTestAppWPF.App.Main()
      

      Relevant log output

      No response

            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: