Skip to content

Commit

Permalink
Frontend.XF.Android: fix NRE when scanning QR codes
Browse files Browse the repository at this point in the history
This commit adds the missing Xamarin.Essential init call
that was causing the ZXing.Net to crash.

This regression was introduced by this commmit: [1]
which updated ZXing.Net.Xamarin from 0.10.x to 2.9.99,
which seems to introduce Xamarin.Essentials as dependency
and needs initializing on Android, as evidenced by: [2]

[1] https://gitlab.com/nblockchain/geewallet/-/commit/9e313fac173bc9d9eab19b90970cbea199dfb6b2
[2] Redth/ZXing.Net.Mobile@5ddfa0e

Stacktrace:
System.NullReferenceException: The current Activity can not be detected. Ensure that you have called Init in your Activity or Application class.
  at Xamarin.Essentials.Platform.GetCurrentActivity (System.Boolean throwOnNull) [0x00018] in D:\a\DotNetEssentials\DotNetEssentials\Xamarin.Essentials\Platform\Platform.android.cs:80
  at Xamarin.Essentials.Permissions+BasePlatformPermission.RequestAsync () [0x00208] in D:\a\DotNetEssentials\DotNetEssentials\Xamarin.Essentials\Permissions\Permissions.android.cs:118
  at ZXing.Net.Mobile.Forms.Android.ZXingScannerViewRenderer.OnElementChanged (Xamarin.Forms.Platform.Android.ElementChangedEventArgs`1[TElement] e) [0x0005d] in D:\a\ZXing.Net.Xamarin\ZXing.Net.Xamarin\ZXing.Net.Mobile.Forms\ZXingScannerViewRenderer.android.cs:59
  at GWallet.Backend.Infrastructure.Report (System.Exception ex, SharpRaven.Data.ErrorLevel _arg1) [0x00017] in C:\geewallet\src\GWallet.Backend\Infrastructure.fs:131
  at GWallet.Backend.Infrastructure.LogOrReportCrash (System.Exception ex) [0x00000] in C:\geewallet\src\GWallet.Backend\Infrastructure.fs:150
  at GWallet.Backend.Infrastructure.OnUnhandledException (System.Object _arg1, System.UnhandledExceptionEventArgs args) [0x0000c] in C:\geewallet\src\GWallet.Backend\Infrastructure.fs:162
  at [email protected] (System.Object delegateArg0, System.UnhandledExceptionEventArgs delegateArg1) <0x783f80cdf8 + 0x00043> in <94e6baede217a6cfa3c49f143dcc2e81>:0

See https://gitlab.com/nblockchain/geewallet/-/merge_requests/143
  • Loading branch information
aarani authored and knocte committed Sep 1, 2022
1 parent 0f39c3e commit fabe424
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/GWallet.Frontend.XF.Android/MainActivity.fs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type MainActivity() =
base.OnCreate (bundle)
Xamarin.Forms.Forms.Init (this, bundle)

Xamarin.Essentials.Platform.Init(this, bundle)
ZXing.Net.Mobile.Forms.Android.Platform.Init()

this.LoadApplication (new GWallet.Frontend.XF.App ())

0 comments on commit fabe424

Please sign in to comment.