1

Working on a Xamarin Forms app (Android & iOS) When trying to create my connection to an easy table I have in an Azure Mobile App my Visual Studio Freezes for around 7 seconds and then when it comes back it has exited the code and the Android app, running in debug is permanently frozen.

When stepping through the code it steps over client = new MobileServiceClient(appUrl); and then when it hits the next line it freezes. But it doesn't matter what the next line is. I have put many different things after and it still freezes. Also, this is in a try/catch block, yet no exception is thrown.

I also wanted to see if the problem was server side. But both Post and Get with PostMan works fine. So I think my server is fine. Not completely sure though...

Here is some of the code:

public class ChatStorageAzureService : IChatStorageAzureService
{
    public MobileServiceClient client { get; set; }
    private IMobileServiceSyncTable<MessageViewModel> chatTable;
    public static bool UseAuth { get; set; } = false;

    private static ChatStorageAzureService instance;
    public static ChatStorageAzureService Instance => instance ?? (instance = new ChatStorageAzureService());

    public async Task InitializeAsync()
    {
        if (client?.SyncContext?.IsInitialized ?? false)
            return;

        var appUrl = "http://"MY-WEBSITE".azurewebsites.net/";
        try
        {
            client = new MobileServiceClient(appUrl);

            var path = "syncstore.db";

            var store = new MobileServiceSQLiteStore(path);

            store.DefineTable<MessageViewModel>();

            await client.SyncContext.InitializeAsync(store);

            chatTable = client.GetSyncTable<MessageViewModel>();
        }
        catch (Exception e)
        {
            Debug.WriteLine("Exception thrown in Initialize: " + e);
            throw;
        }
    }

The InitializeAsync has been called in Async methods. It has been called with .Wait() method in a constructor. It has been called with button presses or in page creations. I have tried a ton of different ways to call. But it always freezes.

One thing that I think is weird is that my server code, is one project containing both the SignalR hub code and the Easy Table, yet you access them through different web addresses, For example "http://"SignalR".azurewebsites.net/" and "http://"EasyTable".azurewebsites.net/" Again PostMan is able to access both the tables and the SignalR and the SignalR works on the Android project. But I dont know if having to domains is bad. I am new... if you could not tell already, lol!

I followed this Tutorial for the Easy Table integration and when I did it in a separate project it worked fine. I am trying to integrate it into my actual project and that is where I am having all these problems.

I also turned on debugging with Azure and it doesnt seem like my app ever even reaches the service. No call is ever met. I think. But again I am new to debugging with Azure, so I might not know how to do it right. I followed this Tutorial for setting up Azure debugging

Thanks for any and all help!

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123

2 Answers2

0

Your path is incorrect. It needs to be a directory path, for example on iOS it is /<AppHome>/Library/<YourAppName>/syncstore.db.

We can leverage MobileServiceClient.DefaultDatabasePath to get the default database path in a cross-platform manner.

var path = Path.Combine(MobileServiceClient.DefaultDatabasePath, "syncstore.db");

Feel free to reference this Xamarin.Forms Sample App that uses Azure Mobile Service Client:

https://github.com/brminnick/UITestSampleApp/blob/master/Src/UITestSampleApp/Services/AzureService.cs

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
  • Thanks for the info. But that does not seem to be the problem. The line that is messing everything up is the client = new MobileServiceClient(appUrl); I did try changing the Path code to your suggestion. But it is still broke. Also if I keep the path the way I have it and just move it above the cliney =.... line along with the var store =... page it works fine, until I hit the client=... line. But the weird thing is it always freeze after I "step In" to the next line. What gives!?!? – John Butler Dec 22 '17 at 20:48
  • Dang! Try comparing the project I shared in the link to your project to see if there’s something else we missed! – Brandon Minnick Dec 23 '17 at 01:32
  • Our code is VERY different. And while I could probably copy paste your way of doing things, without any tutorial behind it I will not understand it. The code I am going off is https://github.com/jamesmontemagno/app-coffeesync/blob/master/CoffeeApp.Shared/Model/Azure/AzureService.cs and the tutorial to accompany it is linked in the origianl post. I appreciate you posting yours, and while it helps I dont understand it that well. Like what the heck is Lazy<> ? and that is how you seem to create the Client. – John Butler Dec 23 '17 at 15:40
0

So I finally got it to work!!! "How?" you ask. I went on 2 week vacation, came back, started a again. Copied the new URL of the tut project into my actual project, did some testing. And then this is the big thing, I then put the same address I had been using back into my app, and... it just worked.... I did NOTHING to the code, and now it seems to work... So almost a month of work time lost and all I had to do was just put a different URL in, run it, and then put the original URL back in.... Lovely. I am guessing it cleared out some weird temp file that was messing up the program or something... even though I erased the temp files countless times... I don't get it, but onward I go!