locked
EWS Managed API - How to deal with SyncFolderItems throwing an exception? RRS feed

  • Question

  • Here's a snippet of my code:

    ExchangeSyncFolderItemsResult result = new ExchangeSyncFolderItemsResult();
    bool syncAgain = true;
    int actualChangeCount = 0;
    while (syncAgain)            
    {
        PropertySet props = new PropertySet(PropertySet.FirstClassProperties);
        props.Add(EmailMessageSchema.InternetMessageId);
        ChangeCollection<ItemChange> icc = exchange.SyncFolderItems(folderId,PropertySet.FirstClassProperties, null, 512, SyncFolderItemsScope.NormalItems, result.getSyncState());
         foreach (ItemChange ic in icc)
         {
             // etc.
         }
         
         // etc.
         result.setSyncState(icc.SyncState);
    }

    In one particular folder in one particular user's mailbox, I'm getting an exception:

    This property was requested, but it wasn't returned by the server.
    2014-02-10 14:11:52.1648|FATAL|DSFCMSEprocess01|   at Microsoft.Exchange.WebServices.Data.PropertyBag.get_Item(PropertyDefinition propertyDefinition)
       at Microsoft.Exchange.WebServices.Data.Item.get_DateTimeSent()

    My question is how do I deal with this?  Since an exception is thrown, I don't have a valid icc.SyncState returned.  Without that, I can't update my saved SyncState for the next call within the same folder, which means that as long as that item remains in the folder I'm going to get the same error every time.  I also don't get an ItemId back for the item that caused the exception, so I can't build an IEnumerable<ItemId> to pass as the ignoredItemIds.  So how do I get past this?

    BTW: I do not have access to the mailbox where this problem is occurring, and as of now it is unlikely that I will get access, so I don't know anything about the particular item that caused this exception. Any advice as to how to get that info would also be appreciated.

    -rhs

    Tuesday, February 11, 2014 10:36 PM

All replies

  • It looks like you using the JAVA api ?

    From the errors your getting I would say this is a bug in Java Managed API, its expecting the DateTimeSent property to be always set which is generally the case but its possible that it may not be. If you want to reproduce the issue Create a Draft item in a Mailbox then use a MAPI editor like OutlookSpy or MFCMapi to delete the DateTimeSent DateTime Mapi property and then see if you get the same issue if you try and Sync against that folder.

    If you can get access to the problem mailbox then you could try running Sync code in the EWSEditor http://ewseditor.codeplex.com/ to test it as well, the regular managed API doesn't seem to have this issue.

    The other thing you can try is changing your propertySet to IdOnly and then use LoadPropertiesForItems to load the properties rather then using the ItemChanges collection.

    Cheers
    Glen

    Wednesday, February 12, 2014 5:24 AM
  • The code is C#, not Java.  (No foreach in Java that I'm aware of, but I did have to think for a minute because the other project I'm working on right now is a mix of Java and C -- but that one has nothing to do with Exchange.)

    I used PropertySet.FirstClassProperties because that's what the examples I found used, and I think I read somewhere that FirstClassProperties would be adapdtive to the types of items, but it seems to not be the case -- at least when retrieving multiple items that could have different sets of properties. 

    Doing IdOnly and a LoadProperties seems like it might be the best solution, though I'm afraid that if I don't first somehow weed out the item(s) that don't have DateTimeSent I might get the same result there.  Will have to try it out. (Thanks for the hint about creating a draft.  That makes sense.  I'm pretty new at Exchange dev, but 20 years of Lotus Notes where drafts are pretty much defined by lack of a SentDate item, so I should have figured that out myself. We exclude the Drafts folder from this code, but I guess a draft can be found in any folder that the user puts one in.)   I could certainly do a fall-back if it throws an error and go into code that retrieves the properties for one item at a time.

    Re it being a possible bug in the managed API, that thought did cross my mind.  My first priority is a workaround, but I do think I'll open a support case at some point to report it.



    Wednesday, February 12, 2014 3:06 PM
  • Hmmm... I did a test by moving a message from the Drafts folder into my Inbox and running my code against the Inbox.  No exception was thrown, so either the item that is causing the problem at my customer site isn't an ordinary draft, or I'm getting different behavior in my environment than I am at the customer site. I guess it's possible that different versions of Exchange may behave a little differently when they encounter an item without a DateTimeSent property when processing a SyncFolderItems request.

    Obviously, I have to have a way to deal with this; but being able to reproduce it is pretty important because I can't test my workaround without it.

    Friday, February 14, 2014 8:07 PM
  • You can go in with a MAPI editor like OutlookSpy or MFCMapi and delete the property. I can't reproduce the error your getting if I do that however so without having access the source Mailbox it's a hard issue to guess at(If you can get access to the sourcemailbox doing a quick test with the EWSEditor would by a good test). What version of the Managed API are you using ?. Could be an Item in that folder is corrupted in some way.

    Cheers
    Glen

    Monday, February 17, 2014 5:30 AM