Skip to content
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

[Bug] Realm accessed from incorrect thread in UWP app #2045

Closed
tipa opened this issue Oct 2, 2020 · 4 comments · Fixed by #2046
Closed

[Bug] Realm accessed from incorrect thread in UWP app #2045

tipa opened this issue Oct 2, 2020 · 4 comments · Fixed by #2046
Assignees

Comments

@tipa
Copy link

tipa commented Oct 2, 2020

Goals

Initialize a "main thread" realm instance in my app constructor and use it across my app (in the main thread).
There were no issues with that code until the NuGet version 5.x - it worked fine in 4.3.0.
Having a static realm instance like this makes it much easier for me to work with Realm in various app pages as well as in the app background task

Expected Results

No crash

Actual Results

When trying to access the realm instance:
System.Exception: 'Realm accessed from incorrect thread.'

Steps to Reproduce

Realm.GetInstance() in app constructor
realm.Write() later on in MainPage

Code Sample

RealmCrash.zip

Version of Realm and Tooling

  • Client SDK Version: 5.1.1
@nirinchev
Copy link
Member

That's an annoying implementation detail in the way UWP/WPF installs the synchronization context on the main thread. We special cased it for WPF, but seems like we'll need it for UWP too.

@nirinchev nirinchev self-assigned this Oct 2, 2020
@nirinchev
Copy link
Member

This has been fixed and will be released with the next Realm version. If you want to give it a shot, check out the nightly builds section of the readme on how to get the latest build from master (I just merged the PR, so it should be up in the packages section in ~20-30 minutes).

@tipa
Copy link
Author

tipa commented Oct 2, 2020

Thanks for the quick fix!

@nirinchev
Copy link
Member

No worries, thanks for the repro - that made it super straightforward to repro and test the fix 😄

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants