I am wondering if I am missing anything here… My understanding is that I should be able to get the ID property (but not set it) after deserializing. As it stands, the ID property is not brought along at all:
namespace CableSolve.Orders.Core.Dto
{
[Serializable]
[XmlRoot("Task"), SoapType("Task")]
public class TaskDto : IDto
{
// ReSharper disable ConvertToAutoPropertyWithPrivateSetter
private int _id;
public int ID { get { return _id; } }
// ReSharper restore ConvertToAutoPropertyWithPrivateSetter
public int TaskSequence { get; set; }
public TaskDto()
{
}
}
}
Ideally my ID would not be settable. If I give the ID property an automatic, private setter — XML Serializer throws a fit. I thought the workaround for that was described here, but it does not appear to work for non-collections? I would prefer to not have to rewrite using DataContract at this point in time.
‘CableSolve.Web.Api.WorkflowServicesProxy.TaskDto’ does not contain a definition for ‘ID’ and no extension method ‘ID’ accepting a first argument of type ‘CableSolve.Web.Api.WorkflowServicesProxy.TaskDto’ could be found
The deserialiser is just C# code. It requires a setter for a serialised property. Thus you must have a getter and setter for every property that is to be serialised by XML serializer; it also requires the property to be public.
Also you do not need an empty constructor for the class.
For more info, see http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx