Search code examples
c#win-universal-appzxing

ZXing.Net.Mobile Barcode scanner error when I call Scan() method


I am trying to implement the barcode scanner into my windows universal app. I am using ZXing.Net.Mobile

var _scanner = new MobileBarcodeScanner(this.Dispatcher);                    
var result = await _scanner.Scan();

Then, the Visual Studio stops at this line

if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();

So, how to solve this problem?


Solution

  • I don't get an exception, the VS just highlights the line mentioned above. I believe the problem is that I don't have ZXing.Net.Mobile.WindowsUniversal in the references. but I can't find it in NuGet.

    You can click the "Tools" of vs and choose the label "NuGet Package Manager" then select the "Manage NuGet Package for Solution", in the "Browse" label, search for "ZXing.Net.Mobile", if you are working on an Uwp app, choose "ZXing.Net.Mobile", if you are using Xamarin for developing, choose "ZXing.Net.Mobile.Forms", in the right of the window, select your project and click Install.

    Here is a picture I complete installed this package: enter image description here

    I've tested your code in a button click event, your posted code can be debugged after installed this package.

    But if I debug it on the local machine, the same error occurred, this is possible because there is no scanner can be initialized on my computer, so when I test it on mobile emulator, this error won't happen.

    if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
    

    Some other problems can also cause it, if my answer can not solve your problem, you can add a comment.

    I think the exception is "Access is denied"

    This is your newest comment about your problem, when you want to use ZXing in your app, you will need to open your project's manifest file, choose the "Capabilities" label, and in the left, enable "Internet(Client)", "Microphone" and "Webcam" capabilities. Just tested, if you didn't enable this capabilities, the same error will also occurred on mobile emulator. This is also a possible cause of this problem.