xamarin-fingerprint: `NullReferenceException` on AuthenticationRequestConfiguration with beta

1.4.6-beta3 seems to introduce a NullReferenceException on Android.

Steps to reproduce

var fingerprintRequest = new AuthenticationRequestConfiguration(AppResources.FingerprintDirection)
            {
                AllowAlternativeAuthentication = true,
                CancelTitle = AppResources.Cancel,
                FallbackTitle = AppResources.LogOut
            };
            var result = await _fingerprint.AuthenticateAsync(fingerprintRequest);

Expected behavior

No crash

Actual behavior

Crash

Crashlog

11-28 07:50:23.051 I/MonoDroid(26966): UNHANDLED EXCEPTION:
11-28 07:50:23.056 I/MonoDroid(26966): System.NullReferenceException: Object reference not set to an instance of an object.
11-28 07:50:23.056 I/MonoDroid(26966):   at Plugin.Fingerprint.Dialog.FingerprintDialogFragment.OnCreateView (Android.Views.LayoutInflater inflater, Android.Views.ViewGroup container, Android.OS.Bundle savedInstanceState) [0x0000d] in C:\Projekte\xamarin-fingerprint\src\Plugin.Fingerprint.Android\Dialog\FingerprintDialogFragment.cs:156 
11-28 07:50:23.056 I/MonoDroid(26966):   at Android.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_inflater, System.IntPtr native_container, System.IntPtr native_savedInstanceState) [0x00020] in <e975227ac8644a30bb0866117325de0d>:0 
11-28 07:50:23.056 I/MonoDroid(26966):   at (wrapper dynamic-method) System.Object:b6ecdc56-c6bc-4f57-b633-f35b4213ced3 (intptr,intptr,intptr,intptr,intptr)

Configuration

Version of the Plugin: 1.4.6-beta3

Platform: Android 8.0

Device: Nexus 5X

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 28 (18 by maintainers)

Commits related to this issue

Most upvoted comments

All: I was getting this same error. I had the CrossFingerprint configuration in place in the OnCreate in MainActivity.cs but I noticed that the current activity was null. After reviewing a few other unrelated (but similar) posts I added this line before the CrossFingerprint.SetCurrentActivityResolver config and that solved it for me:

CrossCurrentActivity.Current.Activity = this;

So my OnCreate looks something like this:

protected override void OnCreate(Bundle bundle)
{
    TabLayoutResource = Resource.Layout.Tabbar;
    ToolbarResource = Resource.Layout.Toolbar;

    CrossCurrentActivity.Current.Activity = this;

    // Fingerprint auth
    CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);

    base.OnCreate(bundle);

    Forms.Init(this, bundle);
    Xamarin.FormsMaps.Init(this, bundle);
    LoadApplication(new App());
}

Hope this helps. If there are issues with this approach please let me know.