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

6

5

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.

Matteroffact answered 26/9, 2018 at 14:22 Comment(1)
This was the change I made: The like looks like this: private const string EmailQueryString = "Kind:email"; ... FindItemsResults<Item> results = exchangeService.FindItems(folderId, EmailQueryString, new ItemView(itemViewSize)); I remove the constant, this "Kind:email" create the failure, not a direct answer for the question but fails even on the FindItems, probably help.Reenareenforce
M
0

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.

Matteroffact answered 26/9, 2018 at 15:47 Comment(0)
R
6

This code worked for me. I needed to add "new PropertySet" to get it to work.

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

But what finally made it work was setting the Exchange version from Exchange2013 to Exchange2015:

Old Code:

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

New code:

    service = new ExchangeService(ExchangeVersion.Exchange2015)
    {
        Credentials = new WebCredentials(user, password),
        TraceEnabled = false,
        TraceFlags = TraceFlags.None
    };
Religion answered 4/2, 2022 at 11:23 Comment(0)
H
2

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.

Haggle answered 24/6, 2019 at 19:51 Comment(0)
R
1

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.

Roccoroch answered 2/10, 2018 at 21:46 Comment(0)
M
0

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.

Matteroffact answered 26/9, 2018 at 15:47 Comment(0)
S
0

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
                                            );
Snowonthemountain answered 30/9, 2018 at 8:6 Comment(0)
R
0

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.

Roccoroch answered 2/10, 2018 at 21:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.