Facebook login/crash at any breakpoint "Object reference not set to an instance of an object"

Hi Folks, I'm trying to get Facebook login working with my Android app. When I debug it without any breakpoints set, it appears to work when I click on the Facebook button and either cancel or login. However, when I debug it, it crashes with "Object reference not set to an instance of an object" at the breakpoint, whereever it's set. I simplified the code to the minimum:


using Android.App;
using Android.OS;
using Xamarin.Facebook;
using Xamarin.Facebook.Login.Widget;

namespace App3
    [Activity(Label = "teambuilder", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity, IFacebookCallback

        protected override void OnCreate(Bundle bundle)
            Xamarin.Facebook.ICallbackManager callbackManager;
            callbackManager = Xamarin.Facebook.CallbackManagerFactory.Create();
            LoginButton _facebookButton;
            _facebookButton = FindViewById<LoginButton>(Resource.Id.facebook_login_button);
            _facebookButton.RegisterCallback(callbackManager, this);

        //protected override void OnActivityResult(int requestCode, Android.App.Result resultCode, Android.Content.Intent data)
        //    base.OnActivityResult(requestCode, resultCode, data);
        //    //callbackManager.OnActivityResult(requestCode, (int)resultCode, data);

        public void OnSuccess(Java.Lang.Object obj)

        public void OnCancel()

        public void OnError(FacebookException fbException)

        protected override void OnRestart()

Starting in a debugger, with only one breakpoint set--at the open curly of OnResume()--I click on the facebook button, then click on "close" to cancel (or login if you want). The debugger breaks at the breakpoint, but it displays the exception. I get an exception in Visual Studio or Xamarin Studio. I don't see any "VM abort".

Stack trace:

0x25 in System.Diagnostics.Debugger.Mono_UnhandledException_internal C#
0x1 in System.Diagnostics.Debugger.Mono_UnhandledException at .../System.Diagnostics/Debugger.cs:122,4 C#
0x20 in object.7d7a5265-2529-4cd4-b377-b7d49a9d8272 C#
0x0 in App3.MainActivity.OnRestart at C:...\MainActivity.cs:44,9 C#
0xA in Android.App.Activity.n_OnRestart at .../generated/Android.App.Activity.cs:4539,4 C#
0x11 in object.7d7a5265-2529-4cd4-b377-b7d49a9d8272 C#

Any ideas how I can debug this without crashing at any breakpoint I set?

The equivalent in Java works perfectly fine. Incidentally, the Java code does not require OnActivityResult() to be defined--all the callbacks work fine. Only in Xamarin do I have to define OnActivityResult() for the callbacks to work. Not sure why. Working with all the latest tools and APIs.



  • KenDominoKenDomino USMember

    I filed a bug for this: https://bugzilla.xamarin.com/show_bug.cgi?id=38230. There is a workaround, but it shouldn't be this way. I wonder if anyone has developed an app with a FB LoginButton for a long time. Regression tests probably wouldn't pick this up because you don't normally have regression tests that run with breakpoints in a debugger, and this only happens while debugging after a FB login.

Sign In or Register to comment.