User.Current not cashing

I opened the ToDo project from GitHub (my_first_realm_app (dot net)) and replaced the AuthUrl var with my realm address. Everything works as expected except for these two issues: First the app crashes here: realm = await Realm.GetInstanceAsync(configuration); I replaced the line with GetInstance(configuration) as a quick fix. Second, the user and the data is not saved locally. The user’s credentials have to be reentered each time the app is initialized, and when the program is offline the data does not populate. I am working in C# with Visual Studio 2010 with Realm version 4.3.0
Any ideas on how to fix these issues. Thanx!

Hi @Jean-Luc_Chalumeau. We’ve been using Realm .NET for a few years. We have found GetInstanceAsync unpredictable. Instead, at app start we await Session.AwaitForDownloadAsync. Then we use Realm.GetInstance. This ensures you are working with an uptodate realm.

You do need to provision for either await GetInstanceAsync or AwaitForDownloadAsync never returning, so work out a mechanism for timing them out. We use this little helper
public static async Task TimeoutAsync(Task mainTask, int timeout = 5000)
Task delayTask = Task.Delay(timeout);
Task winner = await Task.WhenAny(mainTask, delayTask);
bool result = (winner == mainTask);
return result;

Thank you for your suggestion. It worked and fixed the GetInstance issue. Any idea on how to resolve the User.Current and data not being saved locally. Thanx!

My understanding with sync is there is no local database, merely a cache. This cache is cleared if the user is logged out.

The user credentials are also cached so it should not be necessary to login the user again, unless the user has been logged out. At startup we check
UserState loginState = realmUser.State;
if (loginState == UserState.Active)
isLoggedIn = true;

Also don’t use
config.ClientResyncMode = ClientResyncMode.DiscardLocalRealm
as this discards the local cache when the app shuts down.