Reputation: 26668
I am trying to list some events using the C# EWS 2.0 library.
It is using the following code:
public IEnumerable<AppEvent> ListEvents(CalendarFolder folder, DateTime? startDate, DateTime? endDate)
{
var items = new List<AppEvent>();
var now = DateTime.Now;
if (startDate == null) startDate = DateTime.Now;
if (endDate == null) endDate = now.AddDays(14);
FindItemsResults<Appointment> findResults = null;
ServiceResponseCollection<GetItemResponse> appointments = null;
CalendarView view = null;
view = new CalendarView((DateTime)startDate, (DateTime)endDate);
findResults = folder.FindAppointments(view);
if (findResults.Items.Count() == 0) return items;
appointments = Service.BindToItems(findResults.Select(item => item.Id), AppointmentPropertySet);
foreach (GetItemResponse item in appointments)
{
var appointment = item.Item as Appointment;
try
{
if (appointment.IsCancelled) continue;
}
catch (System.NullReferenceException)
{
continue;
}
var evt = AppEvent.FromEWSAppointment(appointment);
items.Add(evt);
}
return items;
}
And AppointmentPropertySet
is as follows:
protected PropertySet AppointmentPropertySet = new PropertySet(
AppointmentSchema.Subject,
AppointmentSchema.Start,
AppointmentSchema.End,
AppointmentSchema.IsAllDayEvent,
AppointmentSchema.IsMeeting,
AppointmentSchema.IsRecurring,
AppointmentSchema.IsCancelled,
AppointmentSchema.IsDraft,
AppointmentSchema.Location,
AppointmentSchema.Resources,
AppointmentSchema.RequiredAttendees,
AppointmentSchema.OptionalAttendees,
AppointmentSchema.LegacyFreeBusyStatus,
AppointmentSchema.Organizer,
AppointmentSchema.Body,
AppointmentSchema.Sensitivity,
AppointmentSchema.AppointmentReplyTime,
AppointmentSchema.AppointmentSequenceNumber,
AppointmentSchema.AppointmentState,
AppointmentSchema.AppointmentType,
AppointmentSchema.ConferenceType,
AppointmentSchema.DateTimeCreated,
AppointmentSchema.Duration,
AppointmentSchema.EndTimeZone,
AppointmentSchema.HasAttachments,
AppointmentSchema.ICalDateTimeStamp,
AppointmentSchema.ICalRecurrenceId,
AppointmentSchema.ICalUid,
AppointmentSchema.Id,
AppointmentSchema.Importance,
AppointmentSchema.IsOnlineMeeting,
AppointmentSchema.IsReminderSet,
AppointmentSchema.IsResponseRequested,
AppointmentSchema.IsUnmodified,
AppointmentSchema.LastModifiedTime,
AppointmentSchema.LegacyFreeBusyStatus,
AppointmentSchema.MeetingRequestWasSent,
AppointmentSchema.MyResponseType,
AppointmentSchema.MeetingWorkspaceUrl,
AppointmentSchema.NetShowUrl,
AppointmentSchema.OriginalStart,
AppointmentSchema.ParentFolderId,
AppointmentSchema.Recurrence,
AppointmentSchema.ReminderDueBy,
AppointmentSchema.ReminderMinutesBeforeStart,
AppointmentSchema.StartTimeZone,
AppointmentSchema.WebClientEditFormQueryString,
AppointmentSchema.WebClientReadFormQueryString
);
We are getting the following error for one of the events. If I remove RequiredAttendees
and OptionalAttendees
from AppointmentPropertySet
, it works fine (albeit, no attendees are returned).
How can I avoid this error, or how can I skip this event so the view returns at least the appointments that are not broken?
System.ArgumentException: Requested value 'User' 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.EwsXmlReader.ReadElementValue[T]()
at Microsoft.Exchange.WebServices.Data.EmailAddress.TryReadElementFromXml(EwsServiceXmlReader reader)
at Microsoft.Exchange.WebServices.Data.Attendee.TryReadElementFromXml(EwsServiceXmlReader reader)
at Microsoft.Exchange.WebServices.Data.ComplexProperty.InternalLoadFromXml(EwsServiceXmlReader reader, XmlNamespace xmlNamespace, String xmlElementName, Func`2 readAction)
at Microsoft.Exchange.WebServices.Data.ComplexProperty.LoadFromXml(EwsServiceXmlReader reader, XmlNamespace xmlNamespace, String xmlElementName)
at Microsoft.Exchange.WebServices.Data.Attendee.TryReadElementFromXml(EwsServiceXmlReader reader)
at Microsoft.Exchange.WebServices.Data.ComplexProperty.InternalLoadFromXml(EwsServiceXmlReader reader, XmlNamespace xmlNamespace, String xmlElementName, Func`2 readAction)
at Microsoft.Exchange.WebServices.Data.ComplexProperty.LoadFromXml(EwsServiceXmlReader reader, XmlNamespace xmlNamespace, String xmlElementName)
at Microsoft.Exchange.WebServices.Data.ComplexPropertyCollection`1.LoadFromXml(EwsServiceXmlReader reader, XmlNamespace xmlNamespace, String localElementName)
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.EwsServiceXmlReader.ReadServiceObjectsCollectionFromXml[TServiceObject](XmlNamespace collectionXmlNamespace, 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.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.ExchangeService.InternalBindToItems(IEnumerable`1 itemIds, PropertySet propertySet, ServiceErrorHandling errorHandling)
at ExchangeAppService.Utilities.API.ExchangeAPI.ListEvents(CalendarFolder folder, Nullable`1 startDate, Nullable`1 endDate) in c:\Users\Some Guy\Documents\Visual Studio 2013\Projects\ExchangeAppService\ExchangeAppService\Utilities\API\Exchange\ExchangeAPI.cs:line 195
Upvotes: 4
Views: 1231
Reputation: 1
An issue was opened in github on 2017/12/15. https://github.com/OfficeDev/ews-managed-api/issues/145
No response yet. We have started hitting this same issue with about 30% of a customers mailboxes, and we're worried this is going to spread
Upvotes: 0
Reputation: 973
Judging by the exception stack trace, I'm pretty sure that your exchange server is replying with an invalid value ("User") for the MailboxType of one (or more) of the Attendees email address.
Looking at the current implementation of the MailboxType enum it seems like the value "User" is invalid even with the latest version.
You should be able to confirm this further by analyzing the soap response that Exchange is returning to you, by tracing it (See How to: Trace requests and responses to troubleshoot EWS Managed API applications), or by using a network analyzer like Fiddler or Wireshark.
If this is the case, I think the only solution is to open an issue on their github repo, and hope they can give you more information or a possible solution to your problem.
Upvotes: 2