smstuebe / xamarin-fingerprint

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

CrossFingerprint.Current.AuthenticateAsync Returns System.NullReferenceException #104

Closed RichardeButler closed 2 years ago

RichardeButler commented 6 years ago

To help us fix your issue, please provide the information in the below template. If something causes a crash, provide as much information as you can gather. Just imagine: we do not know what you are doing!

Note: There is often little we can do without a minimal reproducible sample of the issue, so please provide that in a standalone git repository and link it here.

Steps to reproduce

  1. Upgrade VS 2017 to netstandard 2.0

  2. Upgrade all nuget packages to most recent version

  3. line of code that throws the exception is var auth = await CrossFingerprint.Current.AuthenticateAsync("Authenticate access");

The issue started after I updated VS to version 15.7.1. Before the upgrade it worked fine. Happens on both iOS and Android.

Xamarin version 4.10.0.442 Xamarin.Android SDK version 8.3.0.19 Xamarin.iOS SDK version 11.10.1.177

Expected behavior

Should not throw an exception

Actual behavior

Throws System.NullReferenceException

Crashlog

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

d__10.MoveNext () [0x00018] ## Configuration AndroidManifest.xml mainActivity protected override void OnCreate(Bundle bundle) { CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity); .. } **Version of the Plugin:** e.g. 1.0.0 / 1.0.1-alpha3 1.4.7 **Platform:** e.g. iOS 10.1 / Android 4.4 / ... (including version!!! e.g. Android 5.1 / i0S 10) iOS Android Min version 6 max version 8.1 / iOS 10.1 **Device:** All
smsissuechecker commented 6 years ago

Hi @RichardeButler,

I'm the friendly issue checker. Thanks for using the issue template :star2: I appreciate it very much. I'm sure, the maintainers of this repository will answer, soon.

RichardeButler commented 6 years ago

The issue is related to .NetStandard 2.0.3. Downgraded to 2.0.1 and this corrected the issue.

danielbarrosamorim commented 6 years ago

Hey @RichardeButler, how did you downgrade to 2.0.1? I've tried to add the Nuget Package but it seems to keep using the version 2.0.3 Thanks.

RichardeButler commented 6 years ago

I used NuGet package manager. go to the installed tab. from the drop down select 2.0.1. NuGet Package Manager will uninstall 2.0.3 and then install 2.0.1. Hope this helps.

Sent from my Verizon, Samsung Galaxy smartphone -------- Original message --------From: Daniel Amorim notifications@github.com Date: 7/4/18 3:44 PM (GMT-05:00) To: smstuebe/xamarin-fingerprint xamarin-fingerprint@noreply.github.com Cc: Rick Butler Rick.butler2@gmail.com, Mention mention@noreply.github.com Subject: Re: [smstuebe/xamarin-fingerprint] CrossFingerprint.Current.AuthenticateAsync Returns System.NullReferenceException (#104) Hey @RichardeButler, how did you downgrade to 2.0.1? I've tried to add the Nuget Package but it seems to keep using the version 2.0.3

Thanks.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread. {"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/smstuebe/xamarin-fingerprint","title":"smstuebe/xamarin-fingerprint","subtitle":"GitHub repository","main_image_url":"https://assets-cdn.github.com/images/email/message_cards/header.png","avatar_image_url":"https://assets-cdn.github.com/images/email/message_cards/avatar.png","action":{"name":"Open in GitHub","url":"https://github.com/smstuebe/xamarin-fingerprint"}},"updates":{"snippets":[{"icon":"PERSON","message":"@danielbarrosamorim in #104: Hey @RichardeButler, how did you downgrade to 2.0.1? I've tried to add the Nuget Package but it seems to keep using the version 2.0.3\r\nThanks."}],"action":{"name":"View Issue","url":"https://github.com/smstuebe/xamarin-fingerprint/issues/104#issuecomment-402549120"}}} [ { "@context": "http://schema.org", "@type": "EmailMessage", "potentialAction": { "@type": "ViewAction", "target": "https://github.com/smstuebe/xamarin-fingerprint/issues/104#issuecomment-402549120", "url": "https://github.com/smstuebe/xamarin-fingerprint/issues/104#issuecomment-402549120", "name": "View Issue" }, "description": "View this Issue on GitHub", "publisher": { "@type": "Organization", "name": "GitHub", "url": "https://github.com" } }, { "@type": "MessageCard", "@context": "http://schema.org/extensions", "hideOriginalBody": "false", "originator": "AF6C5A86-E920-430C-9C59-A73278B5EFEB", "title": "Re: [smstuebe/xamarin-fingerprint] CrossFingerprint.Current.AuthenticateAsync Returns System.NullReferenceException (#104)", "sections": [ { "text": "", "activityTitle": "Daniel Amorim", "activityImage": "https://assets-cdn.github.com/images/email/message_cards/avatar.png", "activitySubtitle": "@danielbarrosamorim", "facts": [

] } ], "potentialAction": [ { "name": "Add a comment", "@type": "ActionCard", "inputs": [ { "isMultiLine": true, "@type": "TextInput", "id": "IssueComment", "isRequired": false } ], "actions": [ { "name": "Comment", "@type": "HttpPOST", "target": "https://api.github.com", "body": "{\n\"commandName\": \"IssueComment\",\n\"repositoryFullName\": \"smstuebe/xamarin-fingerprint\",\n\"issueId\": 104,\n\"IssueComment\": \"{{IssueComment.value}}\"\n}" } ] }, { "name": "Close issue", "@type": "HttpPOST", "target": "https://api.github.com", "body": "{\n\"commandName\": \"IssueClose\",\n\"repositoryFullName\": \"smstuebe/xamarin-fingerprint\",\n\"issueId\": 104\n}" }, { "targets": [ { "os": "default", "uri": "https://github.com/smstuebe/xamarin-fingerprint/issues/104#issuecomment-402549120" } ], "@type": "OpenUri", "name": "View on GitHub" }, { "name": "Unsubscribe", "@type": "HttpPOST", "target": "https://api.github.com", "body": "{\n\"commandName\": \"MuteNotification\",\n\"threadId\": 336389184\n}" } ], "themeColor": "26292E" } ]

6Hat commented 4 years ago

For me this exact issue occurred when I upgraded the Plugin.Fingerprint by Sven-Michael from version 1.49 to version 2.0. I was able to fix the issue by downgrading back to 1.49

smstuebe commented 4 years ago

@6Hat can you please share some information? Maybe create a issue with a more detailed report (fill issue template)? This issue is very old. If there are any issues with 2.0.0 I'm very interested in fixing them.

RakeshRaviGovindhan commented 4 years ago

Fix of NullRefrenceException

//Some times this may get exception //CrossFingerprint.SetCurrentActivityResolver(() => CrossCurrentActivity.Current.Activity);

//you can use this code if you are getting the exception. CrossFingerprint.SetCurrentActivityResolver(() => this);

thedee commented 4 years ago

I updated from: Plugin.Fingerprint 1.4.9 >>> 2.1.1 and now get the following error when doing: var result = await CrossFingerprint.Current.AuthenticateAsync(conf);

System.InvalidOperationException: Expected current activity to be 'AndroidX.Fragment.App.FragmentActivity' but was 'RPT.Droid.MainActivity'. You need to use AndroidX. Have you installed Xamarin.AndroidX.Migration in your Android App project!?
  at Plugin.Fingerprint.FingerprintImplementation.NativeAuthenticateAsync (Plugin.Fingerprint.Abstractions.AuthenticationRequestConfiguration authRequestConfig, System.Threading.CancellationToken cancellationToken) [0x0003c] in d:\a\1\s\src\Plugin.Fingerprint\Platforms\Android\FingerprintImplementation.cs:100 
  at Plugin.Fingerprint.Abstractions.FingerprintImplementationBase.AuthenticateAsync (Plugin.Fingerprint.Abstractions.AuthenticationRequestConfiguration authRequestConfig, System.Threading.CancellationToken cancellationToken) [0x000e1] in d:\a\1\s\src\Plugin.Fingerprint\Abstractions\FingerprintImplementationBase.cs:24 
  at RPT.App.RequestBiometric (System.String text) [0x000ec] in D:\src\CC\00 - Main\Applications\RPT\Mobile\Source\Dev\Dk\RPT\RPT\App.xaml.cs:848

I do have Xamarin.AndroidX.Migration 1.0.6.1 installed on my android project.

It appears to be the error raised from this in NativeAuthenticateAsync

if (!(CrossFingerprint.CurrentActivity is FragmentActivity)) 
                throw new InvalidOperationException($"Expected current activity to be '{typeof(FragmentActivity).FullName}' but was '{CrossFingerprint.CurrentActivity?.GetType().FullName}'. " +
                                                    "You need to use AndroidX. Have you installed Xamarin.AndroidX.Migration in your Android App project!?");
ricardocardoso41 commented 2 years ago

I updated from: Plugin.Fingerprint 1.4.9 >>> 2.1.1 and now get the following error when doing: var result = await CrossFingerprint.Current.AuthenticateAsync(conf);

System.InvalidOperationException: Expected current activity to be 'AndroidX.Fragment.App.FragmentActivity' but was 'RPT.Droid.MainActivity'. You need to use AndroidX. Have you installed Xamarin.AndroidX.Migration in your Android App project!?
  at Plugin.Fingerprint.FingerprintImplementation.NativeAuthenticateAsync (Plugin.Fingerprint.Abstractions.AuthenticationRequestConfiguration authRequestConfig, System.Threading.CancellationToken cancellationToken) [0x0003c] in d:\a\1\s\src\Plugin.Fingerprint\Platforms\Android\FingerprintImplementation.cs:100 
  at Plugin.Fingerprint.Abstractions.FingerprintImplementationBase.AuthenticateAsync (Plugin.Fingerprint.Abstractions.AuthenticationRequestConfiguration authRequestConfig, System.Threading.CancellationToken cancellationToken) [0x000e1] in d:\a\1\s\src\Plugin.Fingerprint\Abstractions\FingerprintImplementationBase.cs:24 
  at RPT.App.RequestBiometric (System.String text) [0x000ec] in D:\src\CC\00 - Main\Applications\RPT\Mobile\Source\Dev\Dk\RPT\RPT\App.xaml.cs:848

I do have Xamarin.AndroidX.Migration 1.0.6.1 installed on my android project.

It appears to be the error raised from this in NativeAuthenticateAsync

if (!(CrossFingerprint.CurrentActivity is FragmentActivity)) 
                throw new InvalidOperationException($"Expected current activity to be '{typeof(FragmentActivity).FullName}' but was '{CrossFingerprint.CurrentActivity?.GetType().FullName}'. " +
                                                    "You need to use AndroidX. Have you installed Xamarin.AndroidX.Migration in your Android App project!?");

I'm having this exact problem, any solution?

smstuebe commented 2 years ago

@ricardocardoso41 is your MainActivity a AndroidX.Fragment.App.FragmentActivity?

ricardocardoso41 commented 2 years ago

@ricardocardoso41 is your MainActivity a AndroidX.Fragment.App.FragmentActivity?

My Main Activity is a Xamarin.Forms.Platform.Android.FormsApplicationActivity. If I try to change it to AndroidX.Fragment.App.FragmentActivity I get an error saying that no LoadApplication method was found. Maybe this a simple problem but is my first time using Xamarin and I'm not very into it yet.

smstuebe commented 2 years ago

I don't support deprecated Apps ^^ You need to use FormsAppCompatActivity https://docs.microsoft.com/en-us/xamarin/xamarin-forms/platform/android/#platform-support