ews-managed-api icon indicating copy to clipboard operation
ews-managed-api copied to clipboard

Call to SyncFolderHierarchy with FolderSchema.WellKnownFolderName causes exception

Open utillity opened this issue 9 years ago • 3 comments

Hi,

I would like to cache the folder hierarchy of a mailbox using the ExchangeService.SyncFolderHierarchy() API method.

public void UpdateFolderList(SyncTarget syncTarget, ExchangeService svc)
{
  var ci = syncTarget.ConnectionInfos.GetObject<ExchangeConnectionInfos>();
  PropertyDefinitionBase[] props =
  {
    FolderSchema.Id, FolderSchema.ParentFolderId, FolderSchema.DisplayName, FolderSchema.FolderClass
  };
  var propSet = new PropertySet(props);
  while (true)
  {
    var result = svc.SyncFolderHierarchy(new FolderId(WellKnownFolderName.MsgFolderRoot),  
      propSet, ci.FolderHierarchySyncState);
...

This code works just fine. But the FolderChange.FolderId.FolderName (of enum type WellKnownFolderName?) and FolderChange.Folder.WellKnownFolderName (of equal type) are both always null. So adding FolderSchema.WellKnownFolderName to the PropertySet above would be the best bet. But now as soon as I call the API method, the following exception appears:

System.ArgumentException: Requested value 'imcontactlist' was not found.
at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)
at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)
at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)
at Microsoft.Exchange.WebServices.Data.EwsUtilities.Parse[T](String value)
at Microsoft.Exchange.WebServices.Data.GenericPropertyDefinition`1.Parse(String value)
at Microsoft.Exchange.WebServices.Data.TypedPropertyDefinition.LoadPropertyValueFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag)
at Microsoft.Exchange.WebServices.Data.PropertyBag.LoadFromXml(EwsServiceXmlReader reader, Boolean clear, PropertySet requestedPropertySet, Boolean onlySummaryPropertiesRequested)
at Microsoft.Exchange.WebServices.Data.SyncResponse`2.ReadElementsFromXml(EwsServiceXmlReader reader)
at Microsoft.Exchange.WebServices.Data.ServiceResponse.LoadFromXml(EwsServiceXmlReader reader, String xmlElementName)
at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.ParseResponse(EwsServiceXmlReader reader)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadResponse(EwsServiceXmlReader ewsXmlReader)
at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.ReadResponseXml(Stream responseStream)
at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.ReadResponse(IEwsHttpWebResponse response)
at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
at Microsoft.Exchange.WebServices.Data.ExchangeService.SyncFolderHierarchy(FolderId syncFolderId, PropertySet propertySet, String syncState)
at ...Server.Sync.Exchange.ExchangeServiceFactory.UpdateFolderList(SyncTarget syncTarget, ExchangeService svc)
at ...Server.Sync.Exchange.ExchangeMailboxProviderInfo.Validate(SyncTarget syncTarget)
at ...Client.Windows.UserEntity.MailboxesEditViewModel.<ValidateExecute>b__33_0() in ...MailboxesEditViewModel.cs:line 165

It seems the enumeration in the managed API is behind Outlook 2016 features? Is there any workaround for this?

I am using the latest NuGet package (2.2.0).

utillity avatar Jan 02 '16 10:01 utillity

which packet did you use for connecting to Exchange? would you give me a document which contains the package you used?

ali-heydari-1989 avatar Feb 13 '19 02:02 ali-heydari-1989

I guess package from nuget.

pkropachev avatar Feb 13 '19 05:02 pkropachev

Don't know if you solved this but I ran into the same problem. Limiting the request for FolderSchema.WellKnownFolderName to the WellKnownFolderName.MsgFolderRoot solved my issue. This also works fine in WellKnownFolderName.RecoverableItemsRoot

Convilguous avatar Jul 08 '22 13:07 Convilguous