Q:

Method returning early, not completing

This method never gets past the foreach loop. No matter what I place after it, it doesn't get ran. Even if the book object had no contact objects in it, it shouldn't just skip the rest of the code. This is being used for a contact selector in an app i'm working on, any ideas on what's going on here? Thanks
public class UserContactService : IUserContactService
{
    public List<Contact> GetContacts()
    {
        List<Contact> contacts = new List<Contact>();
        var book = new Xamarin.Contacts.AddressBook();
        Console.WriteLine("Before loop");
        foreach (Contact c in book)
        {
            contacts.Add(c);
        }
        Console.WriteLine(DateTime.Now);
        return contacts;
    }
}

A:

With Xamarin, you need to check that the user has granted permissions to access the contact book first, otherwise your foreach is going to error (because book will never contain contacts).
To get permissions from the app user, you can do that within Xamarin too:
if (!await book.RequestPermission()) {
    Console.WriteLine("Permission denied by user or manifest");
    return;
}

I'd also wrap your foreach in a try/catch for additional error messaging etc:
try {      
    foreach (Contact c in book)
    {
        contacts.Add(c);
    }
} catch (Exception ex) {
    Console.WriteLine(ex);
}

More info on Xmarin Mobile here: https://components.xamarin.com/view/xamarin.mobile

