Hello,
I have a requirement to unread email from outlook365 using C#. For this, i am using Exchange web service (EWS). When I read emails, i am getting an error in the below line.(highlighted as bold)
foreach(EmaiMessage email in _service.FindItems(WellKnownFolderName.Inbox, new ItemView(100)))
{
}
Error : foreach statement cannot operate on variable of type 'Task
DId i do anything wrong? Please suggest me.
Thanks!

Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Mar 28, 2022, 12:35 PM EDT
Ashok Shanmugavel28 reputationPosted Mar 29, 2022, 5:33 AM EDT
Thanks for your reply Muhammad. When i use the below code, I am getting the error.
foreach(EmaiMessage email in _service.FindItems(WellKnownFolderName.Inbox, new ItemView(100)).Items)
{
// Your Code
}
Error : CS1061 : 'Task>' does not contain a defintion for 'Items' and no accessible extension method 'Items' accepting a first argument of type 'Task>' could be found(are you missing a using directive or an assembly reference?)
I am included all the namespace but still getting this error.
Thanks!
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Mar 29, 2022, 6:09 AM EDT
Ashok Shanmugavel28 reputationPosted Mar 29, 2022, 6:23 AM EDT
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Mar 29, 2022, 8:03 AM EDT
Ashok Shanmugavel28 reputationPosted Mar 29, 2022, 9:36 AM EDT
No, I am getting another error in the Items.
var emailMessages = findResults.Items.Cast(); --> debugger is showing an error in the Items.
Error : CS1061 : 'Task>' does not contain a defintion for 'Items' and no accessible extension method 'Items' accepting a first argument of type 'Task>' could be found(are you missing a using directive or an assembly reference?)
Sachin SinghRank #66 · 26.2K reputationPosted Mar 30, 2022, 3:45 AM EDT