CrossGeeks/GeofencePlugin

Crash in GeofenceImplementation.OnConnected callback NullReferenceException

Closed this issue · 1 comments

Our app has reported a crash, the exception is:

System.NullReferenceException: Object reference not set to an instance of an object

with the following stack trace:

GeofenceImplementation+<OnConnected>d__59.MoveNext ()
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state)

Since this seems to happen inside the OnConnected method, I'm guessing the issue is that accessing var location = await mFusedLocationProviderClient.GetLastLocationAsync(); is the problem

var location = await mFusedLocationProviderClient.GetLastLocationAsync();

Because the instance variable mFusedLocationProviderClient is only initialized in the IsLocationEnabled method:

mFusedLocationProviderClient = LocationServices.GetFusedLocationProviderClient(Android.App.Application.Context);

Seems possible to have OnConnected executed by a thread before IsLocationEnabled is executed (or would be executed by a different thread).

@jasonmereckixpo Thanks for fixing this issue.