Xamarin Sample - QuickJournal


#1

Using Realm 3.0 in .Net Just looking through the samples and noticed the QuickJournal does not successfully login a User(neither Regular or Admin) with such code:

    private const string AdminUsername = "realm-admin";
    private const string AdminPassword = "";
    private const string ServerUrl = "192.168.4.29:9080";

// Login the admin user
var credentials = Credentials.UsernamePassword(AdminUsername, AdminPassword, createUser: false);
var admin = await User.LoginAsync(credentials, new Uri($“http://{ServerUrl}”));

Any suggests ?


#2

What’s the exception that gets thrown?


#3

Thanks for the reply.

The Client ‘Xamarin Live’ logs suggest Object type does not match of the System.Collections.Generic.List

Visual Studio is very quite about the failure but fails @ var admin …

This is the second sample I’ve tried… the first a .Net console app for attaching a listener to the Object Server which worked by authenticating without exceptions to the same ROS with same admin user.

not sure about the next steps


#4

Can you place a try-catch block around this method and inspect the exception? That should give us more information.


#5

Thanks for the suggestion:

The block produces this stack trace:

at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0004b] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at NInterpret.Interpreter.callAMethod (NInterpret.AMethod m, NInterpret.AType[] ptypes, NInterpret.AType[] genericMethodArgs, System.Collections.Generic.Dictionary2[TKey,TValue] genericArgsIndex, System.Object[] args, System.Collections.Generic.List1[T] byRefArgs, Microsoft.FSharp.Core.FSharpOption1[T] byRefTarget, System.Object target, System.Boolean virtualCall) [0x0049b] in <5a7d38ec7eef0f2aa7450383ec387d5a>:0 at NInterpret.Interpreter.callMethodReference (System.Collections.Generic.Dictionary2[TKey,TValue] gargs, Mono.Cecil.MethodReference ms, System.Boolean virtualCall) [0x00384] in <5a7d38ec7eef0f2aa7450383ec387d5a>:0
at NInterpret.Interpreter.interpretBlock (System.Object[] args, System.Object[] locals, Mono.Cecil.Cil.Instruction initialInstruction, Microsoft.FSharp.Collections.FSharpSet1[T] inTries, Microsoft.FSharp.Core.FSharpOption1[T] lastException) [0x00fb7] in <5a7d38ec7eef0f2aa7450383ec387d5a>:0
at NInterpret.Interpreter.interpretBlock (System.Object[] args, System.Object[] locals, Mono.Cecil.Cil.Instruction initialInstruction, Microsoft.FSharp.Collections.FSharpSet1[T] inTries, Microsoft.FSharp.Core.FSharpOption1[T] lastException) [0x0013c] in <5a7d38ec7eef0f2aa7450383ec387d5a>:0

are there any Realm specific exception available?


#6

I find it surprising that you’re getting F# exceptions while the code you posted seems like C#. Am I missing something here?


#7

nope… nothing but good old C# found within Xamarin,Forms :smile:


#8

I have no idea what’s going on then - this stacktrace doesn’t make any sense :frowning: Can you upload your project so I can try to run it locally?


#9

Thanks for your input much appreciated :smile: _smile:

This is the QuickJournal sample found here

I have modified and added one method for signing into a sync-realm

    public JournalEntriesViewModel()
    {

        AddEntryCommand = new Command(AddEntry);
        DeleteEntryCommand = new Command<JournalEntry>(DeleteEntry);

        ConnectToRealm().ContinueWith(task =>
        {
            IsBusy = false;
            if (task.Exception != null)
            {/*TODO:some error message*/}
        });

     

    }

    async Task ConnectToRealm()
    {
        Realms.Sync.User admin = null;
        try
        {
            var credentials = Credentials.UsernamePassword(AdminUsername, AdminPassword, createUser: false);
            admin = await User.LoginAsync(credentials, new Uri($"http://{ServerUrl}"));
        }
        catch (Exception ex)
        {
            string _message;
            _message = ex.Message;
        }
        
        IsBusy = true;

        var config = new SyncConfiguration(admin, new Uri($"realm://{ip}:9080/~/journal"));
        _realm = Realm.GetInstance(config);

        Entries = _realm.All<JournalEntry>();
     

    }

Cheers!


#10

I tried to follow the steps you outlined and was able to successfully authenticate and create objects. Please make sure that your device can “see” the server url that you’re providing.


#11

Thanks for your suggestion.

Earlier, I had the opportunity to successfully use the console app .Net example code found within the topic “creating-event-handlers-in-net” located here

The QuickJournal project is running on the same/same… same device and network etc. using the same credentials and connection info… as such, there is a strong belief the server is visible.

Which version of Realm and Xamarin have you used?

mine:
Realm 3.0
Realm Database 3.0
Realm DataBinding 1.2
Realm Server 1.1

With
Visual Studio 2017 Version 15.7
.Net Version 4.7.02556
Xamarin 4.10.0.442
Xamarin Designer 4.12.264
Xamarin Andriod SDK 8.3.0.19
Xamarin iOS and Mac&Cheese 11.10.1.177 :):grin:


#12

What device are you running the sample on? I don’t suppose it’s the same device as the .NET Core project. And yes, I used the same versions. I’m guessing you’re not using the server SDK on the Xamarin Forms project as those are incompatible.


#13

Hey thanks for your attention. And after a cup of coffee…
I’ve realized you had questioned the deployed device… The device is a Samsung S8 which is on the same network using IP 192.168.4.19 I am able to deploy to this device using the Xamarin Live tool/routine and able to browse using Chrome to the IP 192.168.4.29:9080
I will check with the network guys to see if they’re blocking it from the server some how

We have researched the network and the suggestion is that nothing is blocking the communication between device and server.

Can you share your project’s resources referenced?


#14

We are able to view the error logs from within Xamarin Live :slight_smile:

[LogEntry: Time=2018-05-11 12:54:58 PM -07:00, Level=Error, Title=Uncaught Exception, Message=Constructor on type ‘System.Threading.ThreadLocal1[[System.Collections.Generic.IDictionary2[[System.String, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.WeakReference`1[[NInterpret.InterpretedObject, NInterpret.Xamarin.Droid, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]’ not found. (MissingMethodException)]


#15

Login for Realm server ,it return null user


#16

Hello videp Unsure of your comment Are you attempting to login using this same setup and project?


#17

Hello ergodaveh
My code :slight_smile:private void OnSubmit()
{
Realm instance = null;
try
{
var _users = LoginRealm();
SyncConfiguration config = new SyncConfiguration(_users.Result, new Uri(Constants.SyncServerUri));

            instance = Realm.GetInstance(config);
        }
        catch (Exception e)
        {
            string error = e.ToString();
            instance = Realm.GetInstance();
        }

    }

    async Task<User> LoginRealm()
    {

        Realms.Sync.Credentials credentials = Realms.Sync.Credentials.UsernamePassword(Constants.DefaultUser, Constants.DefaultPassword, createUser: false);
        return await Realms.Sync.User.LoginAsync(credentials, new Uri(Constants.AuthServerUri));
    }

#18

Hi vidiep This pattern seems to fails to an Instance of Realm in both the Sync’d or local realm

Anyone with any suggestions?


#19

What is the version of ROS that you’re trying to connect to?


#20

…‘pardon the delayed response’

We are using ROS 3.3.0