BlazorLeaflet icon indicating copy to clipboard operation
BlazorLeaflet copied to clipboard

BlazorLeaflet not working with WebAssembly and .net core 3.1

Open mennowo opened this issue 4 years ago • 7 comments

Hello,

when I download the repository and run the sample, all works fine. However, when I try integrating a map in my own application, I get this error:

Microsoft.JSInterop.JSException: Could not find 'leafletBlazor' in 'window.window'.

I referenced the BlazorLeaflet.dll file I built myself from my project and added a script reference in index.html. Do I have to do anything beyond that to get it to work?

Thanks! Greets, Menno

mennowo avatar Jul 31 '20 12:07 mennowo

A follow-up: I get the same error when using the lib in a server project.

It does however work (server-side only, not with WebAssembly), when I include the BlazorLeaflet project in my own solution, and reference the project from my web app.

mennowo avatar Jul 31 '20 13:07 mennowo

Same issue here. The only way I manage to run this package is by downloading project and then referencing to my app

losbaltica avatar Oct 09 '20 15:10 losbaltica

Similiar issue in client-side Blazor Webassembly (.net 5.0): "Error: Could not find 'window.leafletBlazor.create' ('leafletBlazor' was undefined)."

Am I missing something? Should I create a new issue for that?

paud0 avatar Dec 17 '20 14:12 paud0

I was having similar issues; resolved them by referencing leaflet.js in index.html/_Host.cshtml. The README doesn't specify to do this, but I believe you have to?

From sample project:

    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css"
          integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
          crossorigin="" />
    <script src="https://unpkg.com/[email protected]/dist/leaflet.js"
            integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
            crossorigin=""></script>

bryanrcarlson avatar Dec 29 '20 19:12 bryanrcarlson

My experience was that with an older browser I got the window.window error, but with newer browsers it seems to work. I actually believe (as far as I can remember) it was a challenge for older browsers with the spread operator ... that is used in the leafletBlazorInterops.js file.

erikthysell avatar Feb 23 '21 08:02 erikthysell

I was getting the same error message as shown above. The fix for me was to add the following line after your leaflet script tag.

<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-WBkoXOwTeyKclOHuWtc+i2uENFpDZ9YPdf5Hf+D7ewM=" crossorigin=""></script>
<script src="_content/BlazorLeaflet/leafletBlazorInterops.js"></script>

I am using Leaflet 1.9.3 and the 0.4.0 alpha release of the BlazorLeaflet library from NuGet. I found this by reviewing the example section and saw this was the only difference between my code and the example code.

BenBurge avatar Jan 26 '23 21:01 BenBurge

Do you have any info about this problem? For me the only possibility to solve this was to add the BlazorLeaflet project to my solution, other combinations had failed.

K2-Software avatar Feb 28 '23 13:02 K2-Software