AspNetMonsters / Blazor.Geolocation

Blazor interop for browers Geolocation apis
MIT License
91 stars 24 forks source link

Readme update and NullReferenceException #10

Open hannespreishuber opened 4 years ago

hannespreishuber commented 4 years ago

try to get it run with 3.0 final protected override async Task OnInitAsync() should be in readme.md protected override async Task OnInitializedAsync()

but at this point I get a NullReferenceException: Object reference not set to an instance of an object. Microsoft.AspNetCore.Components.Server.Circuits.RemoteJSRuntime.BeginInvokeJS(long asyncHandle, string identifier, string argsJson) Microsoft.JSInterop.JSRuntime.InvokeAsync(string identifier, CancellationToken cancellationToken, object[] args) Microsoft.JSInterop.JSRuntime.InvokeWithDefaultCancellation(string identifier, object[] args) System.Threading.Tasks.ValueTask.get_Result() System.Runtime.CompilerServices.ValueTaskAwaiter.GetResult() AspNetMonsters.Blazor.Geolocation.LocationService.GetLocationAsync() in LocationService.cs + var result = await jSRuntime.InvokeAsync("AspNetMonsters.Blazor.Geolocation.GetLocation", requestId); UseGeo.Pages.Index.OnInitializedAsync() in Index.razor + location = await LocationService.GetLocationAsync();

aleksandar-smilevski commented 4 years ago

Hi @hannespreishuber,

I ran into a similar (the same) issue, when trying to read the location of the user using the LocationService. This is the error in the console:

image

I found a workaround by copying the Location.js in the wwwroot of my application https://github.com/AspNetMonsters/Blazor.Geolocation/blob/9a7ab1b06cfeee05a5130e89f7ac9404bddfc126/AspNetMonsters.Blazor.Geolocation/wwwroot/Location.js#L1

And then referencing it in my index.html or _Host.cshtml (if you're using Blazor Server Side).

However, I think when installing the NuGet package the file should be copied to your wwwroot.

Hope that helps :)

P.S. I am a Blazor novice and someone more experienced may give better advice. I am just sharing what fixed my issue