5

I've tried to get contact info in Windows Phone 8.1 SL app by following Quickstart: Selecting user contacts

In my function,

    private async void PickAContactButton_Click(object sender, RoutedEventArgs e)
    {
        var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker();
        contactPicker.desiredFieldsWithContactFieldType.add(Windows.ApplicationModel.Contacts.ContactFieldType.email);
        Contact contact = await contactPicker.PickContactAsync(); // this throws System.NotImplementedException
        // Additional information: The method or operation is not implemented.

        if (contact != null)
        { ... }
     }

Exact same function works in Windows Phone 8.1 RT. ContactPicker class is supported in both WP 8.1 RT and WP 8.1 SL according to this reference.

Any idea what is going on ?

Mangesh
  • 5,491
  • 5
  • 48
  • 71
ToMonika
  • 51
  • 1
  • I am having the same problem for a few hours now... Any updates on this topic? – timtos Dec 15 '14 at 22:54
  • Gives me `System.IO.FileNotFoundException` for `var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker();` and `IList contacts = await contactPicker.PickContactsAsync();` – Mangesh Dec 18 '14 at 05:39
  • Having the same problem. This seems to be some problem with the framework only. Check here https://social.msdn.microsoft.com/Forums/windowsapps/en-US/8b8ab8a9-189a-40e0-8490-36a892118ee2/contactpicker-problem-in-windows-phone-81-silverlight?forum=wpdevelop – Mangesh Dec 18 '14 at 08:46
  • This is a bug and I am going to file it. – Matt Small Jan 02 '15 at 20:02
  • Oh, well, I'm experiencing this behaviour right now, and it has been quite some time since the original question was posted. :( – Michael Antipin Jan 14 '15 at 13:43

1 Answers1

1

I had this behaviour today in my Universal Store App for Win 8.1, so may be this helps you out. I had different exceptions though (FileNotFoundException and just plain System.Exception), so I'm not really certain this is the same issue.

As far as my experiments go, this is what is currently needed to make ContactPicker work:

  • ContactPicker instance must be created in the UI thread
  • contactPicker.DesiredFieldsWithContactFieldType must have exactly one item (0 or >1 items yield exception)

This is what I ended up doing:

// using Windows.ApplicationModel.Core;

// in an async method:
Contact user = null;
AutoResetEvent resetEvent = new AutoResetEvent(false);
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
    CoreDispatcherPriority.Normal, 
    (async ()=>{
      ContactPicker contactPicker = new ContactPicker();
      contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.PhoneNumber);
      user = await contactPicker.PickContactAsync();
      resetEvent.Set();
    }
);
resetEvent.WaitOne();
if (user != null) {
    // do smth
}
Michael Antipin
  • 3,522
  • 17
  • 32