Skip to content

GetCalendarsAsync on Android throws null exception #86

@steffos

Description

@steffos

Thanks for a great plugin! Occasionally I'm seeing the following crash stack trace in my app log when calling GetCalendarsAsync on Android:

Xamarin Exception Stack:
System.NullReferenceException: Object reference not set to an instance of an object
  at Plugin.Calendars.CalendarsImplementation.IterateCursor[T] (Android.Database.ICursor cursor, System.Func`1[TResult] func) <0x7504be4200 + 0x00160> in <66a7b4e231214800b78812276a0f1b58>:0
  at Plugin.Calendars.CalendarsImplementation+<>c.<GetCalendarsAsync>b__13_0 () <0x7504bdd894 + 0x000d3> in <66a7b4e231214800b78812276a0f1b58>:0

Just had a look at the implementation of GetCalendarsAsync for Android:

public Task<IList<Calendar>> GetCalendarsAsync() => Task.Run(() =>
{
var cursor = Query(_calendarsUri, _calendarsProjection);
var calendars = IterateCursor(cursor, () => GetCalendar(cursor));
return calendars;
});

It seems that on some devices when certain conditions are met the cursor query on line 81 returns null. At least that's how I interpret the stack trace.

Im thinking a null check on the cursor variable might fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions