MongoDB.live, free & fully virtual. Register Now MongoDB.live, free & fully virtual. Register Now

Realm Cloud project: Upgrade Realm DotNet to 5.0.1 throws Access on incorrect thread

I have updated Realm and RealmFody to v 5.0.1 (from 4.3.0), in 2 projects.
(Both on Realm Cloud Full Sync).

Both projects now fail to run giving ‘Realm access on incorrect thread’ exceptions.
It behaves as if any callback is treated as a separate thread:

In a WPF Page:

  1. Create Realm instance ( works OK)
  2. Get data from realm (works OK)
  3. Click button on the same page
  4. Callback throws aforementioned exception using the same call as step 2.

E.G.
void ok_Click(object sender, RoutedEventArgs e) {

  Exception thrown on realm access.
  (This is always the UI thread)

}
The problem happens every where, less I get a new realm instance for every query!!
The projects have run well until the update. Problem is, I can’t revert to 4.3.0 because I get a new error when connecting to Realm about ‘encryption specified blah’.

A possible problem: How does the realm DB format on Realm cloud get updated to V10 format to be in sync with 5.0.1 ?

Thanks. Richard

@Richard_Fairall Can you share some code snippets please? Like how you are setting up your viewModel and what your onClick function looks like? Where the Realm setup is taking place, etc.

Here’s a code snippet:

public partial class SimpleLoginDialog : Window
{
    private Realm realm;

    public SimpleLoginDialog(object caller)
    {
        InitializeComponent();
    }

    private void OnWindowLoaded(object sender, RoutedEventArgs e)
    {
        // We should be in the UI thread here
        this.realm = RealmConnector.GetRealmInstance();

        // The call above does:   Realm.GetInstance(realmConfig) 
        // the realmConfig is a static entity

        BuildUsersViewModels();
    }

    private void BuildUsersViewModels()
    {
        // !! This is Ok from this method 
        var users = realm.All<LoginUser>();
    }

    // event from normal  Click="okButton_Click"  in XAML
    private void okButton_Click(object sender, RoutedEventArgs e)
    {
        // this fails when called her. Can be any type of callback (TextChanged etc)
        var users = realm.All<LoginUser>();

        // if I use a local realm instance, it works...
        var localRealm = RealmConnector.GetRealmInstance();
        var result = localRealm.All<LoginUser>();

        if (realm != null)
        {
            realm.Dispose();
        }
        Close();
    }
}

I cannot test at the moment due to the dreaded exception:
“Metadata Realm encryption was specified, but no encryption key was provided.”
This occurs when switching back to version 4.3.0.
I now get this using v 5.0.1 as well, when calling:
var user = await User.LoginAsync(credentials, new Uri(RealmAuthUrl));

I have never specified using encryption. Is it mandatory on 5.0.1?

I was able to reproduce the threading issue - it’s due to a peculiarity in WPF that we’ll have to find a workaround for.

For the encryption issue - it’s a change of behavior between 4.3.0 and 5.0.1. It’s not required to use encryption, but 4.3.0 incorrectly attempted to encrypt some metadata information which then 5.0.1 tries to read unencrypted. Depending on your platform, this metadata is typically stored in a realm-object-server folder, either in the user’s documents folder or locally next to the .exe. You can safely delete that and the error will go away as long as you don’t switch between versions.

1 Like

Thanks a bunch. I’m now back on 4.3.0 which is working OK.

Rich

I filed https://github.com/realm/realm-dotnet/issues/2026 to track our progress. I believe I have a reasonable workaround and if it doesn’t introduce some unexpected issues, I’ll get it released later this week.

1 Like

This has now been fixed and published in a prerelease package: https://github.com/realm/realm-dotnet/packages/399835.

Feel free to give it a try and let me know if you still experience issues. Instructions on how to use the nightly builds can be found here.

1 Like

Hi Nikola
Thank you for the result. I’m having problems with Nuget. Cannot authenticate and will not allow me another chance to connect to GitHub.
I’ve tried common-line method. No luck yet.

The reason I went to 5.0.1 was mainly to move to MongoDB from Realm Cloud. I can wait for a 5.0.2 release. Any rough idea of release date for 5.0.2?

Rich

Hi Richard, apologies for taking so long to reply - I must have misconfigured my notification settings. I agree that the GitHub NuGet feed is a bit of a chore, but at least they offer a way to download the package directly (the download link is under “Assets” on the package page). An official 5.0.2 is expected early next week - I was waiting on some Core fixes that have now been released.

Note, however, that the 5.x series do not yet support synchronization with MongoDB Realm. A beta release with support for it is expected later this fall. If you’re feeling especially adventurous and want to give the very early alphas a spin, let me know and we can share a build out of this PR.

1 Like

Hi Nikola, thanks for the info. I can wait for 5.0.2, or even the dotnet sync update, (Covid-19 has given us the opportunity to delay launch of our apps) I will conquer Nuget!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.