.NET Sync Issue and Questions


#1

I’m using Realm Cloud from Xamarin.Mac, and am having a pretty basic issue- maybe there’s some new APIs that I’m not accessing? It’s my first time using ROS, so apologies if it’s something around that.

I can properly create/authenticate a user, but when I get the realm with that SyncConfiguration it simply creates it locally and doesn’t sync to Realm Cloud. I’ve poured through the documentation to make sure I’m not forgetting something very basic, but I don’t believe I need to force-start the synchronization or anything.

Code is something like the below. Any advice?

public async Task Authenticate(bool needsCreation)
{
    var credentials = Credentials.UsernamePassword("nickname", "password", needsCreation);
    var user = await User.LoginAsync(credentials, Help.RealmDB.AuthUrl);

    //Using optional path below creates/opens a realm with that file name, vs the default.realm
    var config = new SyncConfiguration(user, Help.RealmDB.DataUrl);

    this.backingSyncConfig = config;
}

private SyncConfiguration backingSyncConfig; 

public Realm ActiveUsersRealm => Realm.GetInstance(backingSyncConfig);

Some follow ups:

  • Any Realm.Cloud apis coming? Or will management primarily be through Realm Studio and Realm.Sync. Came up while thinking of creating directories for a user or a group of users. It looks like in the iOS APIs there’s an api for checking if a realm exists, and creating it if not, which includes a subdirectory folder. Something simple like that in .NET would be cool for now.
  • May be off-topic, but any way to access the locally persisted users from the .NET apis? I’d like to be able to display a list of recent users so they don’t have to put in both username and password. Right now I have a local-only workaround for this. Something akin to UserStore from the java APIs maybe?

Thanks all!


#2

I have the same problem. I first tried typing in the demo app and now I have downloaded the source code to make sure I didn’t miss anything. I’m using the native iOS version and not Xamarin.

I can see that users are created when I connect to my cloud url in Realm Studio but there is no realm called ToDo and when I log in as a different user, no tasks are shown. It seems that tasks are stored locally on the device but not synched to the cloud.


#3

I figured it out. There’s a slash at the end of the cloud URL. When I removed this it worked!


#4

Great catch @Softbox, don’t think I would’ve been able to find that.

For the .NET apis the SyncConfiguratin constructor requires a Uri class parameter, with which the trailing slash can’t be configured. From the looks of it, we can mess with the optional parameter but the internal ServerUri is still a Uri, so if the trailing slash is also the issue for .NET, it doesn’t appear it can be worked around on our end.


#5

You’re correct that trailing slashes shouldn’t be an issue for the .NET SDK. Can you share what AuthUrl and DataUrl look like? (feel free to obfuscate some portion of the domain - I’m mostly interested in the scheme and the port).


#6

Using obj-c, I still have the issue, with or without a slash. The user gets created but the realm db does not get sync at all. My app was using Digital Ocean with no problem at all. I want to switch to Realm Cloud, so I just changed the URLs format to what the Realm Cloud ones, using the template from the Git sample, but no sync is happening.


#7

Sure!

//In Help.RealmDB
private const string instanceHostName = "instanceName.us1.cloud.realm.io";

internal static readonly Uri AuthUrl = new Uri("https://" + instanceHostName);
internal static readonly Uri DataUrl = new Uri("realms://" + instanceHostName);

I didn’t use a port because the iOS docs didn’t mention one in theirs.

edit: I’ve also tried adding a directory to the serverUrl (exactly like the docs), which didn’t changed where the realm was stored locally- no sub directory, etc-, as well as naming the realm file specifically, and a combination of each. Neither changes the underlying syncing issue. Like so:

internal static readonly Uri DataUrl = new Uri("realms://" + instanceHostName + "/app");
//and
var config = new SyncConfiguration(user, Help.RealmDB.DataUrl, "realmName.realm");

#8

@nickspag Your URLs look fine to me.

Do you think you could put your code into a repo and share? Feel free to PM if you’d prefer


#9

@Patrick, which Git sample are you using? Can you share your URL format?


#10

I’m using the sample from the obj-c doc using a Sync Realm.
For Realm Cloud, I’m using these URLs:

static const NSString *syncHost = @"myappcloud.realm.io";
static const NSString *syncRealmPath = @"myapp";
serverURL = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"realms://%@/%@", syncHost, syncRealmPath]];

When I siwtch to Digital Ocean URLs, I use these and it’s working fine. I thought I would just need to change the URL and everything would be the same, is that the idea with Realm Cloud? Or we need to update something else?

static const NSString *syncHost = @"myIP";
static const NSString *syncRealmPath = @"myapp";
serverURL = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"realm://%@:9080/~/%@", syncHost, syncRealmPath]];

Looks like I have the same issue as @NickSpag.


#11

Great. Recreated the issue here on iOS:

If you need permission to access my Realm Cloud instance or something, you have it. Let me know if there is any other way I can help.


#12

@nickspag, I was able to get it going on our end. When you create your user, you create a non-admin user. The non-admin user is not allowed to write to the base directory of the Realm instance – meaning they will not have access to this path.

internal static readonly Uri DataUrl = new Uri("realms://" + instanceHostName + "/app");

So either A) make them an admin user or B) write to their user path like:

internal static readonly Uri DataUrl = new Uri("realms://" + instanceHostName + "~/app");

You also need to set your config variable that you pass into Realm.getInstance.

So your authenticate function will have:
syncConfigForActiveUser = new SyncConfiguration(debugUser, dataUrl, "notDefault");

Additionally, I saw some strange behavior with your authentication code and the needsCreated variable, so you may need to look into how that variable is set.

Go ahead and try that change and let me know if that gets you syncing


#13

Exactly the missing part. That fixed my issue.

This is definitively something to write in the doc or update your sample.
Thanks a lot for the help.


#14

Oh, that repo was just a File > New project and the bool was so I didn’t have to delete the user directly in Realm Cloud if I wanted to retry. I cleaned it up and updated it a bit if anyone needs a .NET sample that simply creates an object.

Anyway, I did get it working! I probably tried every combo except simply “~/name” previously- I’m not sure why, but I was messing around too much trying to create directories or change the realm name with the optional path. For what it’s worth, I couldn’t get the optional path to do anything, at least anything that was visible from Realm Cloud. As well, it won’t write a default.realm file, even in the user’s subdirectory. You have to provide a name for it.

Thanks for the help!