C# EWS项在执行代码时丢失loaded属性

C# EWS项在执行代码时丢失loaded属性,c#,.net,exchangewebservices,C#,.net,Exchangewebservices,我正在尝试加载和使用EWS项目的属性。在我的代码执行过程中,对象失去了它的值。 Im正在加载消息ID、附件和主题 FindItemsResults<Item> items = EwsHelper.GetMails(credentials); //Gets the items from the exchange service object. This method populate FindItemResults. It works.

我正在尝试加载和使用EWS项目的属性。在我的代码执行过程中,对象失去了它的值。 Im正在加载消息ID、附件和主题

            FindItemsResults<Item> items = EwsHelper.GetMails(credentials);  //Gets the items from the exchange service object. This method populate FindItemResults. It works.

            //Find correct EmailMessage with messageId (mailInput.MessageId is a param to my code to verify that I found the correct mail.
            string messageId = mailInput.MessageId;                             
            //The Id.UniqueId can be found. The property is loaded inside of the "EwsHelper.GetMails".
            foreach (Item item in items.Where(i => i.Id.UniqueId == messageId))
            {
                //Here im loading all the properties I need once again. I can verify that the object does have loaded property through the debugger. Everything is fine!
                item.Load(new PropertySet(ItemSchema.Subject,
                    ItemSchema.Id, ItemSchema.Attachments));
                if (item == null || !(item is EmailMessage))
                    throw new Exception();

                dynamic fileObj = new ExpandoObject();                  
                //Here the item.Subject (which recently was loaded) is null... Cant figure out why?!
                fileObj.Filename = $"{item.Subject.RemoveInvalidFileNameChar()}.msg";
            }
这是我的密码:

            FindItemsResults<Item> items = EwsHelper.GetMails(credentials);  //Gets the items from the exchange service object. This method populate FindItemResults. It works.

            //Find correct EmailMessage with messageId (mailInput.MessageId is a param to my code to verify that I found the correct mail.
            string messageId = mailInput.MessageId;                             
            //The Id.UniqueId can be found. The property is loaded inside of the "EwsHelper.GetMails".
            foreach (Item item in items.Where(i => i.Id.UniqueId == messageId))
            {
                //Here im loading all the properties I need once again. I can verify that the object does have loaded property through the debugger. Everything is fine!
                item.Load(new PropertySet(ItemSchema.Subject,
                    ItemSchema.Id, ItemSchema.Attachments));
                if (item == null || !(item is EmailMessage))
                    throw new Exception();

                dynamic fileObj = new ExpandoObject();                  
                //Here the item.Subject (which recently was loaded) is null... Cant figure out why?!
                fileObj.Filename = $"{item.Subject.RemoveInvalidFileNameChar()}.msg";
            }
'''

            FindItemsResults<Item> items = EwsHelper.GetMails(credentials);  //Gets the items from the exchange service object. This method populate FindItemResults. It works.

            //Find correct EmailMessage with messageId (mailInput.MessageId is a param to my code to verify that I found the correct mail.
            string messageId = mailInput.MessageId;                             
            //The Id.UniqueId can be found. The property is loaded inside of the "EwsHelper.GetMails".
            foreach (Item item in items.Where(i => i.Id.UniqueId == messageId))
            {
                //Here im loading all the properties I need once again. I can verify that the object does have loaded property through the debugger. Everything is fine!
                item.Load(new PropertySet(ItemSchema.Subject,
                    ItemSchema.Id, ItemSchema.Attachments));
                if (item == null || !(item is EmailMessage))
                    throw new Exception();

                dynamic fileObj = new ExpandoObject();                  
                //Here the item.Subject (which recently was loaded) is null... Cant figure out why?!
                fileObj.Filename = $"{item.Subject.RemoveInvalidFileNameChar()}.msg";
            }
FindItemsResults items=EwsHelper.getMail(凭证)//从exchange服务对象获取项。此方法填充FindItemResults。它起作用了。
//使用messageId查找正确的EmailMessage(mailInput.messageId是我的代码的参数,用于验证我是否找到了正确的邮件。
字符串messageId=mailInput.messageId;
//可以找到Id.UniqueId。该属性加载在“EwsHelper.getMail”中。
foreach(items.Where中的Item(i=>i.Id.UniqueId==messageId))
{
//这里我再次加载我需要的所有属性。我可以通过调试器验证对象是否加载了属性。一切都很好!
item.Load(新属性集)(ItemSchema.Subject,
ItemSchema.Id、ItemSchema.Attachments);
if(item==null | |!(item为EmailMessage))
抛出新异常();
动态fileObj=新的ExpandoObject();
//这里的item.Subject(最近加载的)为空…无法理解为什么?!
fileObj.Filename=$“{item.Subject.RemoveInvalidFileNameChar()}.msg”;
}

“”“

错误消息:在读取该属性的值之前,必须加载或分配该属性。如果在使用属性之前重新加载属性,我可以让它工作。但我不想在代码中一直调用EWS。。。
            FindItemsResults<Item> items = EwsHelper.GetMails(credentials);  //Gets the items from the exchange service object. This method populate FindItemResults. It works.

            //Find correct EmailMessage with messageId (mailInput.MessageId is a param to my code to verify that I found the correct mail.
            string messageId = mailInput.MessageId;                             
            //The Id.UniqueId can be found. The property is loaded inside of the "EwsHelper.GetMails".
            foreach (Item item in items.Where(i => i.Id.UniqueId == messageId))
            {
                //Here im loading all the properties I need once again. I can verify that the object does have loaded property through the debugger. Everything is fine!
                item.Load(new PropertySet(ItemSchema.Subject,
                    ItemSchema.Id, ItemSchema.Attachments));
                if (item == null || !(item is EmailMessage))
                    throw new Exception();

                dynamic fileObj = new ExpandoObject();                  
                //Here the item.Subject (which recently was loaded) is null... Cant figure out why?!
                fileObj.Filename = $"{item.Subject.RemoveInvalidFileNameChar()}.msg";
            }