简体   繁体   中英

Creating a new MobileServiceClient() freezes VS and Android app

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!

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM