为什么我无法访问 HasPicture 属性?
Why can't I access the HasPicture property?
我正在尝试使用 C# 应用程序管理联系人对象。
我正在使用 BindToItems 加载联系人:
ServiceResponseCollection<GetItemResponse> responses = service.BindToItems(itemIds, PropertySet.FirstClassProperties);
foreach (var responseItem in responses)
{
contactDict.Add(responseItem.Item.Id, (Contact)responseItem.Item);
}
然后我尝试通过将其属性与我的存储值进行比较来检查联系人是否已更改。
return exchangeContact.Surname != user.Surname
|| exchangeContact.CompanyName != user.Company
...
|| (!exchangeContact.HasPicture && user.ThumbnailPhoto != null)
但是当我尝试访问 HasPicture 属性 时,抛出异常。
ServiceObjectPropertyException: This property was requested, but it wasn't returned by the server.
检查调试器,Microsoft.Exchange.WebServices.Data.Contact
的其他属性也会抛出此异常。例子是:
- 生日
- 联系人来源
- 图标索引
- 归一化正文
- 正文
- 邮政地址索引
- 结婚纪念日
为什么我无法访问这些属性?它们不包含在 FirstClassProperties 中吗?但是 this article 说 HasImage 是 Contact 对象的 FirstClassProperty。
根据 BastianW 的评论,您可以使用 Contact.TryGetProperty
方法检查帐户是否有图片。
bool HasPicture;
exchangeContact.TryGetProperty(ContactSchema.HasPicture, out HasPicture);
我正在尝试使用 C# 应用程序管理联系人对象。
我正在使用 BindToItems 加载联系人:
ServiceResponseCollection<GetItemResponse> responses = service.BindToItems(itemIds, PropertySet.FirstClassProperties);
foreach (var responseItem in responses)
{
contactDict.Add(responseItem.Item.Id, (Contact)responseItem.Item);
}
然后我尝试通过将其属性与我的存储值进行比较来检查联系人是否已更改。
return exchangeContact.Surname != user.Surname
|| exchangeContact.CompanyName != user.Company
...
|| (!exchangeContact.HasPicture && user.ThumbnailPhoto != null)
但是当我尝试访问 HasPicture 属性 时,抛出异常。
ServiceObjectPropertyException: This property was requested, but it wasn't returned by the server.
检查调试器,Microsoft.Exchange.WebServices.Data.Contact
的其他属性也会抛出此异常。例子是:
- 生日
- 联系人来源
- 图标索引
- 归一化正文
- 正文
- 邮政地址索引
- 结婚纪念日
为什么我无法访问这些属性?它们不包含在 FirstClassProperties 中吗?但是 this article 说 HasImage 是 Contact 对象的 FirstClassProperty。
根据 BastianW 的评论,您可以使用 Contact.TryGetProperty
方法检查帐户是否有图片。
bool HasPicture;
exchangeContact.TryGetProperty(ContactSchema.HasPicture, out HasPicture);