none
[E2007][E2010][EWSMA][C#]Clear work days and GetUserAvailability fails with NullReferenceException RRS feed

  • Question

  • 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: 

    Wednesday, February 29, 2012 2:59 PM

All replies

  • Not sure if there's a question in there?

    If the user has no days checked as work days, he will have no availabliity.

    I'd trap the error.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    Wednesday, March 28, 2012 9:49 PM
  • Yeah sorry, there wasn't really a question in my post.

    I know I can trap the error and once trapped I can assume that specified user does not have availability.

    But what if I try to schedule an appointment for let's say 5 persons. Then I would fill the array of AttendeeInfo with the email addresses of those 5 users. If one of them has unticked all working days then GetUserAvailability will raise an exception meaning that I am not able to find a schedule and there is no way to find out which user does not have availability. Only workaround is to probe the attendees one by one but then I will lose the appointment suggestion feature.

    Only workaround seems to be not using the EWS Managed API but accessing the Web Service directly. Pity.

    Wednesday, May 16, 2012 2:25 PM
  • Just tested with Managed API 2.0 preview and the problem still occurs.

    Is there any other way to inform Microsoft about this (obvious) bug cause apparently they don't read this forum.

    Tuesday, August 21, 2012 1:04 PM
  • The issue is solved in the open sourced EWS API code, see here:

    https://github.com/OfficeDev/ews-managed-api/issues/51

    Now waiting for a new DLL to be released.

    Friday, May 27, 2016 8:49 AM