Ashok Shanmugavel

Ashok Shanmugavel

  • NA
  • 12
  • 1.2k

Error in foreach statement cannot operate on variable of type

Mar 28 2022 3:28 PM

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<FindItemsResults<Item>>' because 'Task<FindItemsResults<Item>>' does not contain a public instance defintion for 'GetEnumerator'

DId i do anything wrong? Please suggest me.

Thanks!


Answers (8)