Skip to content

Opening ZXing Failed: System.NullReferenceException #718

@Magnabatt

Description

@Magnabatt

Hi All, I feel this might be a double up but i have not been able to find a solution for the below error. Please let me know if a solution has been found?

I have recently updated VS to 15.6.7 and subsequently updated to Xamrin.Forms 2.5.1.444934 with Zxing.Net.Mobile 2.4.1 using .NETStandard 2.0. Since doing this I now get a null reference error each time I call the script.

Also I have only seen the error on Android (testing iOS tonight)

Here is the error:

***** ERROR ***** BtnScanQR_Clicked - Opening ZXing Failed: System.NullReferenceException: Object reference not set to an instance of an object.
at ZXing.Mobile.MobileBarcodeScanner.GetContext (Android.Content.Context context) [0x0001f] in <57b37b10a314448c8d6b2b9155539100>:0
at ZXing.Mobile.MobileBarcodeScanner.Scan (Android.Content.Context context, ZXing.Mobile.MobileBarcodeScanningOptions options) [0x00015] in <57b37b10a314448c8d6b2b9155539100>:0
at ZXing.Mobile.MobileBarcodeScanner.Scan (ZXing.Mobile.MobileBarcodeScanningOptions options) [0x00001] in <57b37b10a314448c8d6b2b9155539100>:0
at ZXing.Mobile.MobileBarcodeScannerBase.Scan () [0x00006] in <5cc6d3dca85f4634ba661b03b5b196fa>:0
at App.MainPage+<BtnScanQR_Clicked>d__2.MoveNext () [0x00023] in C:\Users\Admin\source\repos\App\App\App\MainPage.xaml.cs:67

In my MainActivity.cs I call the following after my Forms.Int:
//QR code reader
global::ZXing.Net.Mobile.Forms.Android.Platform.Init();

And this is the script with in my click event on the MainPage.cs:

//Open QR scanner for code scanning
private async void BtnScanQR_Clicked(object sender, EventArgs e)
{
try
{
var scanner = new MobileBarcodeScanner();
var result = await scanner.Scan();
strAccessToken.Text = result.Text.Trim();
}
catch (Exception ex)
{
GlobalScript.DebugMessages("ERROR", "BtnScanQR_Clicked", "Opening ZXing Failed: " + ex);
}
}

Even rolling back to my original versions of each package I'm now still having the same error.

Any assistance would be appretiated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions