sabitertan / BlazorBarcodeScanner

Barcode Scanner component for Blazor using zxing-js Interop
MIT License
92 stars 37 forks source link

New Blazor Wasm project .net8 throws Could not find 'Helpers.setDotNetHelper' #64

Open aschilr opened 4 months ago

aschilr commented 4 months ago

I created a new .net8 Blazor Wasm project and inserted only Blazor Barcode Scanner as described. Inserted the component in the Home.razor and got the following error:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Could not find 'Helpers.setDotNetHelper' ('Helpers' was undefined). Error: Could not find 'Helpers.setDotNetHelper' ('Helpers' was undefined). at https://localhost:7083/_framework/blazor.web.js:1:734 at Array.forEach () at l.findFunction (https://localhost:7083/_framework/blazor.web.js:1:702) at b (https://localhost:7083/_framework/blazor.web.js:1:5445) at https://localhost:7083/_framework/blazor.web.js:1:3238 at new Promise () at y.beginInvokeJSFromDotNet (https://localhost:7083/_framework/blazor.web.js:1:3201) at Object.ri [as invokeJSJson] (https://localhost:7083/_framework/blazor.web.js:1:165152) at https://localhost:7083/_framework/dotnet.runtime.8.0.3.lxiirgj8ch.js:3:178111 at xl (https://localhost:7083/_framework/dotnet.runtime.8.0.3.lxiirgj8ch.js:3:178945)

AmenallahBarkaoui commented 3 months ago

I think you just need to add the following lines to wwwroot\index.html (for server side _Host.cshtml) before the closing body tag as mentioned in the doc:

<script src="_content/BlazorBarcodeScanner.ZXing.JS/BlazorBarcodeScanner.js"></script>
michielvh2002 commented 1 month ago

I have the same problem and I added those lines. I will come back if I find the cause.

Update: you also have to install the package in the server and add the script tags to your _Host.cshtml file, not your index.html in the client. This is poorly explained in the docs. (Yes this is for WASM, not server side or combined)