C#Exchange Service突然给出错误属性标签仅对Exchange Exchange2015或更高版本有效 [英] C# Exchange Service suddenly giving error The property Hashtags is valid only for Exchange Exchange2015 or later versions

查看:113
本文介绍了C#Exchange Service突然给出错误属性标签仅对Exchange Exchange2015或更高版本有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C#编写的Windows服务,该服务会轮询Exchange服务器以处理发送到无人参与电子邮件箱的邮件.

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

导致崩溃的行是:

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

具体错误是:

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

我不在任何地方使用或访问Hashtag,所以大概它包含在BasePropertySet.FirstClassProperties中.

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.

我正在使用最新的EWS稳定版:Exchange.WebServices.Managed.Api 2.2.1.1

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

BasePropertySet仅具有另一个项IdOnly,而我所追求的属性是InternetMessageId,所以我认为我只会使用它:

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

原来该属性未覆盖InternetMessageId以获取ID ...

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

给出错误的代码部分没有更改,据我所知,没有受影响的Exchange的Office 365更新.

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.

有人以前有这个错误吗?我已经用Google搜索了,但没有得到任何点击.

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

尝试不定期将服务安装在另一台计算机上,该服务特定于其所在的计算机.

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.

推荐答案

已解决.原来是特定电子邮件中的内容.

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>
    }
} 

因此,获取每个电子邮件的属性,而不是一起获取.必须通过列表来完成,因为这就是LoadPropertiesForItems的作用.

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.

在这种情况下,其中一封电子邮件具有导致错误的某些内容(可能是Hashtags属性).

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.

这篇关于C#Exchange Service突然给出错误属性标签仅对Exchange Exchange2015或更高版本有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆