Exchange Web Service – “You must load or assign this property before you can read its value” error message when trying to read message property

Recently I was writing some C# code to connect to Exchange Web Service and get email attachments. While trying to get “From” email address property, I got an exception “You must load or assign this property before you can read its value”.

The problem is that even when you have the message item, property values are not loaded, and hence can not be read. What you need to do then is call Load() method on message object.

FindItemsResults findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(mailboxPageSize));

foreach (Item item in findResults.Items)
{
      EmailMessage message = EmailMessage.Bind(service, item.Id, new PropertySet(ItemSchema.Attachments));

      message.Load();

      string fromAddress = message.From.Address;

      //Do other stuff
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s