CrossGeeks / FacebookClientPlugin

Facebook Client Plugin for Xamarin iOS and Android
MIT License
106 stars 32 forks source link

Cancelling facebook login dialog on android cause crashing #35

Closed gimkim closed 5 years ago

gimkim commented 6 years ago

Bug Information

Version Number of Plugin: 1.4.0 Device Tested On: sony xperia x (oreo) Simulator Tested On: android x86 5.1.1 emulator Version of VS: Community 2017 (15.7.5) Version of Xamarin: 3.2.0.729530-pre2 Versions of other things you are using:

Steps to reproduce the Behavior

-call the CrossFacebookClient.Current.RequestUserDataAsync method -facebook login dialog appeared -close the facebook login dialog (or pressing back ) without loggin in -Exception occured in external (plugin) code cause the app to crash

Expected Behavior

-should not crash -should get the result.Status ==Plugin.FacebookClient.Abstractions.FacebookActionStatus.Canceled

Actual Behavior

-Exception occured in external (plugin) code cause the app to crash

User cancelled facebook login operation09-07 15:35:29.432 I/mono-stdout(12631): User cancelled facebook login operation

Unhandled Exception:

System.NullReferenceException: Object reference not set to an instance of an object.

09-07 15:35:36.176 D/Mono (12631): DllImport attempting to load: '/system/lib/liblog.so'. 09-07 15:35:36.176 D/Mono (12631): DllImport loaded library '/system/lib/liblog.so'. 09-07 15:35:36.176 D/Mono (12631): DllImport searching in: '/system/lib/liblog.so' ('/system/lib/liblog.so'). 09-07 15:35:36.176 D/Mono (12631): Searching for 'android_log_print'. 09-07 15:35:36.176 D/Mono (12631): Probing 'android_log_print'. 09-07 15:35:36.176 D/Mono (12631): Found as 'android_log_print'. 09-07 15:35:36.178 I/MonoDroid(12631): UNHANDLED EXCEPTION: 09-07 15:35:36.192 I/MonoDroid(12631): System.NullReferenceException: Object reference not set to an instance of an object. 09-07 15:35:36.192 I/MonoDroid(12631): at Plugin.FacebookClient.FacebookClientManager+d68.MoveNext () [0x000a8] in C:\Plugins\FacebookClient\src\Plugin.FacebookClient.Android\FacebookClientManager.cs:542 09-07 15:35:36.192 I/MonoDroid(12631): --- End of stack trace from previous location where exception was thrown --- 09-07 15:35:36.192 I/MonoDroid(12631): at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/jenkins/workspace/xamarin-android-d15-7/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152 09-07 15:35:36.192 I/MonoDroid(12631): at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b6_0 (System.Object state) [0x00000] in /Users/builder/jenkins/workspace/xamarin-android-d15-7/xamarin-android/external/mono/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1018 09-07 15:35:36.193 I/MonoDroid(12631): at Android.App.SyncContext+<>c__DisplayClass2_0.b0 () [0x00000] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Android.App/SyncContext.cs:35 09-07 15:35:36.193 I/MonoDroid(12631): at Java.Lang.Thread+RunnableImplementor.Run () [0x00008] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/Java.Lang/Thread.cs:36 09-07 15:35:36.193 I/MonoDroid(12631): at Java.Lang.IRunnableInvoker.n_Run (System.IntPtr jnienv, System.IntPtr nativethis) [0x00008] in /Users/builder/data/lanes/5945/dffc5912/source/monodroid/external/xamarin-android/src/Mono.Android/obj/Release/android-27/mcw/Java.Lang.IRunnable.cs:81 09-07 15:35:36.193 I/MonoDroid(12631): at (wrapper dynamic-method) System.Object.db77f0c4-3513-4533-b08a-6ed1f3740230(intptr,intptr) 09-07 15:35:36.204 W/art (12631): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable 09-07 15:35:36.205 D/Mono (12631): DllImport searching in: 'Internal' ('(null)'). 09-07 15:35:36.205 D/Mono (12631): Searching for 'java_interop_jnienv_throw'. 09-07 15:35:36.205 D/Mono (12631): Probing 'java_interop_jnienv_throw'. 09-07 15:35:36.205 D/Mono (12631): Found as 'java_interop_jnienv_throw'. An unhandled exception occured.

aparnatiwari30 commented 5 years ago

I am also facing the same issue, while cancel or back from the facebook login, Android app is crashing.

aparnatiwari30 commented 5 years ago

I resolve the issue by first calling the CrossFacebookClient.Current.LoginAsync method and then I check the status, if it is equal to FacebookActionStatus.Completed, then I am calling the CrossFacebookClient.Current.RequestUserDataAsync method. For example var loginData = await CrossFacebookClient.Current.LoginAsync(new string[] { "email" }); if (loginData.Status == FacebookActionStatus.Completed) { var jsonData = await CrossFacebookClient.Current.RequestUserDataAsync(new string[] { "id", "email", "first_name", "last_name", "picture" }, new string[] { "email" }); if (jsonData.Status == FacebookActionStatus.Completed) { Debug.WriteLine(jsonData.Data.ToString()); } } else { Debug.WriteLine(loginData.Message); }

mos379 commented 5 years ago

I had that issue too, because I directly used the LoginAsync method in my logic. After separating it into a separate task the response comes back an then the model execution continues... private Plugin.FacebookClient.Abstractions.FacebookResponse<bool> facebookLoginResult; public async Task LoginAsync()
 { facebookLoginResult = await CrossFacebookClient.Current.LoginAsync(new string[] { "email" });

 }

rdelrosario commented 5 years ago

Should be fixed in:

https://www.nuget.org/packages/Plugin.FacebookClient/2.0.1-beta

This version is still in beta but almost releasing a stable version once all tests are completed.

If not fixed after testing this beta please re-open