hamidrezahy / Blazor.QRCode

9 stars 1 forks source link

qrCodeMessage is not defined #2

Closed MrYossu closed 2 years ago

MrYossu commented 2 years ago

Thanks for sharing this, but I can't get it to work.

I followed the instructions on the main page, and added the qrcode.min.js library (as commented in issue #1, maybe you should add that to the main page), but when I try it, I get a 404 on _content/Blazor.QRCode/qrcode.minErrorCallBack.js.

Probably as a result of this, I get the following error in the browser console when I click the "Start scanning" button...

Uncaught ReferenceError: qrCodeMessage is not defined
    at qrcode-init.js:10:13
    at qrCodeErrorCallback (html5-qrcode.min.js:7:1291)
    at p (html5-qrcode.min.js:4:2883)
    at b (html5-qrcode.min.js:4:3240)
    at HTMLVideoElement.d.onplaying (html5-qrcode.min.js:4:3611)

Any ideas what's going wrong?

Thanks again.

MrYossu commented 2 years ago

Ah, looked in the source files and found that the reference should have been...

<script src="_content/Blazor.QRCode/qrcode.min.js"></script>

That fixed the 404, but I still get the same error when it starts scanning.

MrYossu commented 2 years ago

OK, found the problem.

Your embedded JavaScript contains a mistake. The qrcode-init.js code contains the following...

    }, function (errorMessage) {
        DotNet.invokeMethodAsync('Blazor.QRCode', 'OnFailed',
            qrCodeMessage);

Note that the function parameter is named errorMessage but the body of the function assumes it's called qrCodeMessage.

If you fix that, then the error goes away.

However, when I try to scan, the ErrorCallBack C# method is called with the following message...

QR code parse error, error = TypeError: Cannot read properties of null (reading 'getContext')

At this point I got stuck. Any idea what is goingwrong?

hamidrezahy commented 2 years ago

hi, thank you for your time The main drawback was the README.md file and the publish settings. For better use, take a look at the added sample project