smstuebe / xamarin-fingerprint

Xamarin and MvvMCross plugin for authenticate a user via fingerprint sensor
Microsoft Public License
490 stars 115 forks source link

MvvMCross Plugin > System.NullReferenceException on _fingerprint.AuthenticateAsync() #71

Closed ehuna closed 6 years ago

ehuna commented 6 years ago

Steps to reproduce

  1. Using Xamarin Forms, MvvmCross, and MvvmCross.Plugins.Fingerprint
  2. Call _fingerprint.AuthenticateAsync(authenticationReason)
  3. Get a "System.NullReferenceException".

Expected behavior

No Exception, since according to the docs -

"Set the resolver of the current Activity Skip this, if you use the MvvMCross Plugin or don't use the dialog."

Actual behavior

The exception below occurs.

Workaround

Add the line - CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity); to MvxFormsApplicationActivity.OnCreate().

Possible Solution

Update the documentation to add the above line to MvxFormsApplicationActivity.OnCreate(Bundle bundle)

Crashlog

"System.NullReferenceException: Object reference not set to an instance of an object.\n at Plugin.Fingerprint.Dialog.FingerprintDialogFragment+d19.MoveNext () [0x0002f] in C:\Projekte\xamarin-fingerprint\src\Plugin.Fingerprint.Android\Dialog\FingerprintDialogFragment.cs:96 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter`1[ TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at Plugin.Fingerprint.Contract.AndroidFingerprintImplementationBase+d0.MoveNext () [0x00042] in C:\Projekte\xamarin-fingerprint\src\Plugin.Fingerprint.Android\Contract\AndroidFingerprintImplementationBase.cs:17 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.Compi lerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at Plugin.Fingerprint.Abstractions.FingerprintImplementationBase+<AuthenticateAsync>d__1.MoveNext () [0x000b3] in C:\\Projekte\\xamarin-fingerprint\\src\\Plugin.Fingerprint.Abstractions\\FingerprintImplementationBase.cs:18 \n--- End of stack trace from previous location where exception was thrown ---\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0003e] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at System.Runtime. CompilerServices.TaskAwaiter1[TResult].GetResult () [0x00000] in <3fd174ff54b146228c505f23cf75ce71>:0 \n at MYPROJECT.Core.Services.Authentication.FingerprintService+d__7.MoveNext () [0x00067] in C:\code\stash\MYPROJECT\srcm\MYPROJECT.Core\Services\Authentication\FingerprintService.cs:48 "

Configuration

Android Emulator 24x86

smsissuechecker commented 6 years ago

Hi @ehuna,

I'm the friendly issue checker. It seems like (37.50 %) you haven't used our issue template :cry: I think it is very frustrating for the repository owners, if you ignore them.

If you think it's fine to make an exception, just ignore this message. But if you think it was a mistake to delete the template, please close the issue and create a new one.

Thanks!

ehuna commented 6 years ago

Btw, thank you for this plugin - it is amazing!

smstuebe commented 6 years ago

You don't need the CrossCurrentActivity when you use MvvMCross. Have a look at https://github.com/smstuebe/xamarin-fingerprint/blob/master/src/MvvmCross.Plugins.Fingerprint.Android/Plugin.cs

CrossFingerprint.SetCurrentActivityResolver(() => Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity);

does exactly the same. Do you have the bootstrap files in your ios and android project?

ehuna commented 6 years ago

Yes, the bootstrap files where added when I executed 'Install-Package MvvmCross.Plugins.Fingerprint'

The build action for FingerprintPluginBootstrap.cs is set to 'Compile'

Hmm... not sure what I'm doing wrong (?)

Thanks!

smstuebe commented 6 years ago

dupe of #64