Forum Libraries, Components, and Plugins


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Realm DB - exception thrown for no apparent reason

EitanEEitanE Member ✭✭

I have a refresh command in a Xamarin page, and for some reason, Realm throws a RealmInvalidTransactionException when it finishes. In their documentation they wrote about the exception:

An exception, thrown when trying to write data to the Realm outside a Transaction or when trying to create a transaction on a Realm that is opened as read-only.

This is my refresh command:

ICommand refreshCommand = new Command(async () =>
    refreshView.IsRefreshing = true;

    // Refresh everything
    var w = summaryViewModel.Articles[0];

    // wait for articles to finish loading to stop loading indicator
    await Task.Run(() =>
            while (w == summaryViewModel.Articles[0]) ;
        catch (ArgumentOutOfRangeException e)
            while (summaryViewModel.Articles.Count < 5) ;
    refreshView.IsRefreshing = false;

While debugging, I noticed that the exception is only thrown right after the refresh command finishes. No object is trying to access the DB after it, and nothing actually happens after the command finishes its job, so I don't understand why the exception would be thrown.

Sign In or Register to comment.