OfficeDev / ews-managed-api

Other
584 stars 320 forks source link

Call to SyncFolderHierarchy with FolderSchema.WellKnownFolderName causes exception #75

Open utillity opened 8 years ago

utillity commented 8 years ago

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).

ali-heydari-1989 commented 5 years ago

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

pkropachev commented 5 years ago

I guess package from nuget.

Convilguous commented 2 years ago

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