-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InvalidOperationException when removing databound object #1903
Comments
I've figured out how to workaround this. The full example is in the workaround branch of the sample repo (RealmTesterBasic project), but here's a summary. Instead of binding directly to an IQueryable, bind to a list, e.g. List<T> MyCollection = _realm.All<T>().ToList() Then everytime you update the DB, simply reset the list using the above. You can capture updates either through your own logic or with the Realm.RealmChanged event. The same goes for any IList properties in your RealmObjects; convert them to a list in your ViewModel before binding, and update them as appropriate. It's painful, but it works. |
Hi ! I'm facing the same issue and just wonder why can't we use IEnumerable return from _realm.All instead have to call ToList(). The Example from Realm.Net on Github for Xamarin Form also suggest to bind directly to IEnumerable. |
Yes, it definitely works, but as you said this is a problem as it will create issues with the bindings. I manage to reproduce the issue and I'll try to investigate |
Yeah, we were looking into that Friday and came across the culprit, which, ironically, has a comment about replacing the message with a better one 🥲 In any case, we have several avenues we're exploring that will mitigate this and hope to have a fix with our next release. |
Goals
I have a WPF application in which I am binding a ListView to a collection of RealmObjects. My goal is to remove one of these objects from the database
Expected Results
I expected the object to be successfully removed and the bound ListView to update.
Actual Results
System.InvalidOperationException: 'Added item does not appear at given index '1'.'. No stack trace is given. On enabling native code debugging the exception seems to be occuring in realm-wrappers.dll. Slightly misleading as the debug output shows the exception occurs in PresentationFramework.dll
Steps to Reproduce
Bind a ListView to a collection of RealmObjects. Remove an object from the realm instance and you will cause an InvalidOperationException
Code Sample
I've created a repository with a couple of test projects highlighting the issue. Add a few blogs and then select and try to delete one; it should crash with the error.
Note that the first test project mimics my use-case scenario, hence the libraries Stylet and MaterialDesignThemes
Version of Realm and Tooling
The text was updated successfully, but these errors were encountered: