Jonas Stawski

Everything .NET and More

Querying Contacts After Converting to WP7 Mango

If you are working in an application that has been converted from WP7 to WP7.1 (Mango) and are trying to query the contacts like the code below you might get a helpless exception of type System.Exception with the message “Exception”, no InnerException and a StackTrace similar to:

at Microsoft.Phone.UserData.QueryDataEnumerable`1.EnsureInteropInit()
at Microsoft.Phone.UserData.QueryDataEnumerable`1.GetNextBatch(Int32 nextIndex)
at Microsoft.Phone.UserData.QueryDataEnumerator`1.MoveNext()
at Microsoft.Phone.UserData.Contacts.GetContacts(Object state)
at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadPool.WorkItem.doWork(Object o)
at System.Threading.Timer.ring()

   1: Contacts contacts = new Contacts();
   2: contacts.SearchCompleted += (s, e) =>
   3: {
   4:     //Some Code Here
   5: };
   6: contacts.SearchAsync("John", FilterKind.DisplayName, null);

Not very useful!

The problem is that you haven’t indicated Windows Phone to give you capabilities to access the user’s contacts. During the migration from 7.0 to 7.1 Microsoft forgot to append the new capabilities to the WMAppManifest.xml and hence the error.

To solve this simply add the capability to the WMAppManifest.xml

   1: <Capability Name="ID_CAP_CONTACTS"/>


Happy programming!

Comments (1) -

Thanks Jonas, very usefull info!

Reply

Add comment

biuquote
Loading