gpt4 book ai didi

C# Exchange Service 突然报错属性Hashtags is valid only for Exchange Exchange2015 or later versions

转载 作者:太空宇宙 更新时间:2023-11-03 16:58:54 28 4
gpt4 key购买 nike

我有一个用 C# 编写的 Windows 服务,它轮询 Exchange 服务器以处理发送到无人值守邮箱的邮件。

它一直运行良好,直到今天抛出以下错误:-

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.

我没有在任何地方使用或访问主题标签,因此大概它包含在 BasePropertySet.FirstClassProperties 中。

正如我提到的,到目前为止,我一直非常愉快地使用上面的代码,它今天才开始出现这个错误。

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

BasePropertySet 只有一个项目,IdOnly,而我想要的属性是 InternetMessageId,所以我想我应该使用它:

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

原来 InternetMessageId 没有被获取 ID 的属性覆盖...

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 更新。

为了仔细检查,我使用了以前的版本(编译代码,而不是我重新编译的源代码)并安装了它:仍然出现相同的错误。

以前有人遇到过这个错误吗?我用谷歌搜索过,但没有找到任何结果。

编辑:尝试在另一台机器上安装该服务,如果它特定于它所在的机器。

即使使用之前的代码,仍然会出现相同的错误。

最佳答案

这段代码对我有用。我需要添加“新 PropertySet”才能使其正常工作。

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

但最终使它起作用的是将 Exchange 版本从 Exchange2013 设置为 Exchange2015:

旧代码:

    service = new ExchangeService(ExchangeVersion.Exchange2013)
{
Credentials = new WebCredentials(user, password),
TraceEnabled = false,
TraceFlags = TraceFlags.None
};

新代码:

    service = new ExchangeService(ExchangeVersion.Exchange2015)
{
Credentials = new WebCredentials(user, password),
TraceEnabled = false,
TraceFlags = TraceFlags.None
};

关于C# Exchange Service 突然报错属性Hashtags is valid only for Exchange Exchange2015 or later versions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52519985/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com