经过大量调试后,我将一个复杂的托管 EWS 问题细化为以下两个简单的测试用例。第一个有效,第二个失败:
var view = new ItemView(100) { PropertySet = new PropertySet { EmailMessageSchema.Id } };
var findResults = ews.FindItems(WellKnownFolderName.Inbox, view)
var bindResults = ews.BindToItems(findResults.Select(r => r.Id), new PropertySet { EmailMessageSchema.Sender });
// Sanity check
Assert.AreEqual(1, bindResults.Count());
// The results I care about
Assert.AreEqual("David Seiler", bindResults[0].Sender.Name);
Assert.AreEqual("david.seiler@yahoo.com", bindResults[0].Sender.Address);
有人可能会尝试切断BindToItems()
呼叫,并FindItems()
直接使用:
var view = new ItemView(100) { PropertySet = new PropertySet { EmailMessageSchema.Sender } };
var findResults = ews.FindItems(WellKnownFolderName.Inbox, view)
// This part still works fine
Assert.AreEqual(1, findResults.Count());
// So does this
Assert.AreEqual("David Seiler", findResults[0].Sender.Name);
// ...but this fails! Sender.Address is null
Assert.AreEqual("david.seiler@yahoo.com", findResults[0].Sender.Address);
谁能告诉我哪里出错了?从文档看来,这似乎确实可行。并非所有属性都可以读取FindItems()
,这是真的,但是当我尝试访问它们时,这些属性通常会抛出,而且无论如何MSDN 上都有这些属性的列表Sender
,但不在上面。这是怎么回事?