question

dai15002-7450 avatar image
0 Votes"
dai15002-7450 asked JarvanZhang-MSFT commented

Android app crashes when user cancels login with azure providers like Facebook

When a user cancels login by using the code below, then tries to login again, the application crashes. I guess it has something to do with the thread still running in the background for the first canceled login attempt. So my question is, how can I handle the cancelation when inside login page but the login is being manually canceled by user (either by tapping the close button on the login page or press the back button)?

    try
                         {
                             MobileServiceUser user = await MyApp.App.Client.LoginAsync(this, MobileServiceAuthenticationProvider.Facebook, "myApp");

                         }catch(InvalidOperationException e)
                         {
                             //doesnt hit the exception when canceling
                             return false;
                         }
dotnet-xamarin
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,dai15002. There are some confusion about the problem? What api do you use to perform the login? Will it work fine on iOS? Please test to check that. And is there any error occured? Please share the details about the error log.

0 Votes 0 ·

I use the Microsoft Azure Provider authentication with rest api. The code below which is called in AppDelegate for iOS works fine:

  var user = await MyApp.App.Client.LoginAsync(UIApplication.SharedApplication.KeyWindow.RootViewController, MobileServiceAuthenticationProvider.Facebook, "myApp");

The only crash error I get from VS2019 is as below:
102514-appcrash.jpg




I assume we are still on the login thread when canceling, and that thread is never destroyed. So when we login again, it tried to re-create the same thread that is already alive..

0 Votes 0 ·
appcrash.jpg (48.7 KiB)

1 Answer

dai15002-7450 avatar image
0 Votes"
dai15002-7450 answered JarvanZhang-MSFT commented

I found out the root cause of this problem. This was because I had updated both Microsoft.Azure.Mobile.Client and Microsoft.Azure.Mobile.Client.SQLiteStore from 4.1.2 to the lastest stable 4.2.0 version.

In the 4.2.1 version, if user canceled the login, the exception InvalidOperationException would actually hit. But in the 4.2.0 version, the exception is not being hit upon canceling and instead causes the whole app to shut down.

So I wonder how to catch the cancel event by user, if anyone knows?







· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

When canceling the login, the connection may have been already opened and but it's not handled correctly. This is related to the source code of the api, it's suggested to report this to the package repo and check if there's any workaround to get rid of this.

1 Vote 1 ·