1

我正在尝试将联系人保存到 Windows Phone (8) 联系人存储。

我的代码没有做任何非标准的事情:

private async Task SaveContactToLocalStore(IMyLocalContact myLocalContact) {

    var store = await ContactStore.CreateOrOpenAsync(ContactStoreSystemAccessMode.ReadWrite,
                ContactStoreApplicationAccessMode.LimitedReadOnly);

    var contact = new StoredContact(store);

    var properties = await contact.GetPropertiesAsync();

    if (!string.IsNullOrWiteSpace(myLocalContact.Nickname) {
        properties.Add(KnownContactProperties.DisplayName, myLocalContact.Nickname);
    }

    /* Several such addition operations are executed, all identical, except for the values */

    await contact.SaveAsync();
}

在标记的函数中的某处,async我调用我的保存函数:

await SaveContactToLocalStore(myLocalCOntact);

我收到以下错误:System.InvalidCastException在 contact.SaveAsync()

完整的错误文本:

System.InvalidCastException: Specified cast is not valid.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()

我什至不知道从哪里开始调查。MSDN 中的示例工作正常。

4

0 回答 0