C# Exchange Service suddenly giving error The property Hashtags is valid only for Exchange Exchange2015 or later versions

醉酒当歌 提交于 2019-12-11 03:06:54

问题


I have a Windows Service written in C# that polls an Exchange server to process mails to an unattended email box.

It's been working fine, until today when it's throwing up the following error:-

EXCEPTION: Microsoft.Exchange.WebServices.Data.ServiceVersionException: The property Hashtags is valid only for Exchange Exchange2015 or later versions.
   at Microsoft.Exchange.WebServices.Data.PropertyBag.set_Item(PropertyDefinition propertyDefinition, Object value)
   at Microsoft.Exchange.WebServices.Data.ComplexPropertyDefinitionBase.InternalLoadFromXml(EwsServiceXmlReader reader, PropertyBag propertyBag)
   at Microsoft.Exchange.WebServices.Data.ComplexPropertyDefinitionBase.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.ServiceObject.LoadFromXml(EwsServiceXmlReader reader, Boolean clearPropertyBag, PropertySet requestedPropertySet, Boolean summaryPropertiesOnly)
   at Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader.ReadServiceObjectsCollectionFromXml[TServiceObject](XmlNamespace collectionXmlNamespace, String collectionXmlElementName, GetObjectInstanceDelegate`1 getObjectInstanceDelegate, Boolean clearPropertyBag, PropertySet requestedPropertySet, Boolean summaryPropertiesOnly)
   at Microsoft.Exchange.WebServices.Data.EwsServiceXmlReader.ReadServiceObjectsCollectionFromXml[TServiceObject](String collectionXmlElementName, GetObjectInstanceDelegate`1 getObjectInstanceDelegate, Boolean clearPropertyBag, PropertySet requestedPropertySet, Boolean summaryPropertiesOnly)
   at Microsoft.Exchange.WebServices.Data.GetItemResponse.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.ParseResponse(EwsServiceXmlReader reader, WebHeaderCollection responseHeaders)
   at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadResponse(EwsServiceXmlReader ewsXmlReader, WebHeaderCollection responseHeaders)
   at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.ReadResponseXml(Stream responseStream, WebHeaderCollection responseHeaders)
   at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.ReadResponse(IEwsHttpWebResponse response)
   at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()
   at Microsoft.Exchange.WebServices.Data.MultiResponseServiceRequest`1.Execute()
   at Microsoft.Exchange.WebServices.Data.ExchangeService.InternalLoadPropertiesForItems(IEnumerable`1 items, PropertySet propertySet, ServiceErrorHandling errorHandling)
   at Microsoft.Exchange.WebServices.Data.ExchangeService.LoadPropertiesForItems(IEnumerable`1 items, PropertySet propertySet)
   at MyServiceName.MyServiceName.CheckForNewEmails(ExchangeService service) in C:\TFSOnline\RPM Tools\MyServiceName\MyServiceName\MyServiceName.cs:line 177
   at MyServiceName.MyServiceName.RunACheck(Object state) in C:\TFSOnline\RPM Tools\MyServiceName\MyServiceName\MyServiceName.cs:line 117

The line causing the crash is:

PropertySet properties = (BasePropertySet.FirstClassProperties);
service.LoadPropertiesForItems(emails, properties);

The specific error is:

Microsoft.Exchange.WebServices.Data.ServiceVersionException: 
The property Hashtags is valid only for Exchange Exchange2015 or later versions.

I'm not using or accessing Hashtags anywhere, so presumably it's contained in BasePropertySet.FirstClassProperties.

As I mentioned, I've been using the above code quite happily up to now, it's only started giving this error today.

I'm using the latest EWS Stable Build: Exchange.WebServices.Managed.Api 2.2.1.1

BasePropertySet only has one other item, IdOnly, and the property I'm after is InternetMessageId, so I figured I'd just use that:

PropertySet properties = (BasePropertySet.IdOnly);
service.LoadPropertiesForItems(emails, properties);

Turns out InternetMessageId isn't covered by the property to get IDs...

EXCEPTION: Microsoft.Exchange.WebServices.Data.ServiceObjectPropertyException: 
You must load or assign this property before you can read its value.
   at Microsoft.Exchange.WebServices.Data.PropertyBag.get_Item(PropertyDefinition propertyDefinition)
   at Microsoft.Exchange.WebServices.Data.EmailMessage.get_InternetMessageId()

The section of code giving the error hasn't changed, and as far as I can tell there's been no update to Office 365 that's affected Exchange.

To double-check, I took a previous version (compiled code, not source code that I recompiled) and installed that instead: still got the same error.

Anyone had this error before? I've Googled it but didn't get a single hit.

Edit: Tried installing the service on another machine on the off-chance it was specific to the machine it had been on.

Still get the same error, even with the previous code.


回答1:


Try not to use PropertySet properties = (BasePropertySet.FirstClassProperties);, because it will likely return fields more than you need. (more than 50 properties)

Try load those you need it.

PropertySet ps = new PropertySet(
                                            ItemSchema.Subject,
                                            ItemSchema.InReplyTo,
                                            ItemSchema.Body,
                                            ItemSchema.DateTimeSent,
                                            ItemSchema.DisplayTo,
                                            ItemSchema.Importance,
                                            EmailMessageSchema.From,
                                            ItemSchema.UniqueBody, 
                                            ItemSchema.MimeContent, 
                                            ItemSchema.HasAttachments, 
                                            ItemSchema.Attachments
                                            );



回答2:


You could also try setting the requestedServerVersion in the ExchangeService constructor explicitly to something higher. If this involves Office365, bear in mind that EWS is not receiving further updates.




回答3:


You could also try setting the requestedServerVersion in the ExchangeService constructor explicitly to something higher. For Office365, bear in mind that EWS is not receiving further updates.




回答4:


I had this same issue. I noticed that you and I both did not specify which exchange server we were using. That worked for me for a long time but eventually I got this error. Specifying which exchange server fixed this for me.




回答5:


Solved it. Turns out it was something in a specific email.

Originally the code was ordered as:-

PropertySet properties = (BasePropertySet.FirstClassProperties);
service.LoadPropertiesForItems(emails, properties);

foreach (var email in emails)
{
    try {
        <Process Email>
    }
}

I re-ordered the code as:-

foreach (var email in emails)
{
    try {
        var list = new List<EmailMessage> { email };
        PropertySet properties = (BasePropertySet.FirstClassProperties);
        service.LoadPropertiesForItems(list, properties);
        <Process Email>
    }
} 

So, getting the properties individually for each email, rather than all together. Has to be done via a List, as that's what LoadPropertiesForItems takes.

In this case, one of the emails has something (presumably the Hashtags property) which is causing the error.

Now all the rest of the emails get processed correctly, and the one that causes the error is skipped.

Although annoyingly, because I can't access the properties I can't actually log any information about it.



来源:https://stackoverflow.com/questions/52519985/c-sharp-exchange-service-suddenly-giving-error-the-property-hashtags-is-valid-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!