I'm getting an exception when initializing an XMLSerializer
and passing it an instance of Appointment
(from the EWS API):
Microsoft.Exchange.WebServices.Data.Appointment cannot be serialized because it does not have a parameterless constructor.
Here is my code:
private static string FindAppointmentsAsXmlString(CalendarView calendar, ExchangeService serv)
{
FindItemsResults<Appointment> appointments = serv.FindAppointments(
WellKnownFolderName.Calendar, calendar);
List<Appointment> appointmentsList = appointments.ToList();
var serializer = new XmlSerializer(appointmentsList.GetType());
var writer = new StringWriter();
try
{
serializer.Serialize(writer, appointmentsList);
Console.WriteLine(writer.GetStringBuilder().ToString());
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.ReadLine();
}
return writer.GetStringBuilder().ToString();
}