When a user has unticked all work days in the Calendar options in Outlook and then call GetUserAvailability() the function will fail with a NullReferenceException.
The function is called with AvailabilityOptions.RequestedFreeBusyView=FreeBusy, TimeWindow of 40 hours and AvailabilityData FreeBusy.
It occurs with both Managed API 1.1 and 1.2.
Code to reproduce:
string emailAddress = "testUser@testspot.local";
ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
exchService.AutodiscoverUrl(emailAddress);
AttendeeInfo[] attendees = new AttendeeInfo[1] { new AttendeeInfo(emailAddress) };
AvailabilityOptions options = new AvailabilityOptions();
options.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;
DateTime startDate = DateTime.Today;
TimeWindow timeWindow = new TimeWindow(startDate, startDate.AddDays(7));
// NullReferenceException when calling following function
ews.GetUserAvailability(attendees, timeWindow, AvailabilityData.FreeBusy, options);
StackTrace of the NullReferenceException:
System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Microsoft.Exchange.WebServices"
StackTrace:
at Microsoft.Exchange.WebServices.Data.EwsUtilities.ParseEnumValueList[T](IList`1 list, String value, Char[] separators)
at Microsoft.Exchange.WebServices.Data.WorkingPeriod.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.ComplexProperty.LoadFromXml(EwsServiceXmlReader reader, String xmlElementName)
at Microsoft.Exchange.WebServices.Data.WorkingHours.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.ComplexProperty.LoadFromXml(EwsServiceXmlReader reader, String xmlElementName)
at Microsoft.Exchange.WebServices.Data.AttendeeAvailability.LoadFreeBusyViewFromXml(EwsServiceXmlReader reader, FreeBusyViewType viewType)
at Microsoft.Exchange.WebServices.Data.GetUserAvailabilityRequest.ParseResponse(EwsServiceXmlReader reader)
at Microsoft.Exchange.WebServices.Data.ServiceRequestBase.ReadResponse(EwsServiceXmlReader ewsXmlReader)
at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.ReadResponse(HttpWebResponse response)
at Microsoft.Exchange.WebServices.Data.SimpleServiceRequestBase.InternalExecute()
at Microsoft.Exchange.WebServices.Data.GetUserAvailabilityRequest.Execute()
at Microsoft.Exchange.WebServices.Data.ExchangeService.GetUserAvailability(IEnumerable`1 attendees, TimeWindow timeWindow, AvailabilityData requestedData, AvailabilityOptions options)
at ExchangeAutodiscover.Form1.button2_Click(Object sender, EventArgs e) in C:\My Projects\Visual C#\ExchangeAutodiscover\Form1.cs:line 72
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at ExchangeAutodiscover.Program.Main() in C:\My Projects\Visual C#\ExchangeAutodiscover\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: