Geometry objects are DataContracts and can be serialized with the regular DataContractSerializer, but if you try to use the System.Runtime.Serialization.NetDataContractSerializer it will fail because it requires the PointCollection type to be marked as a data contract (which it is not).
// Create a geometry
Polyline polyline = new Polyline();
PointCollection points = new PointCollection();
points.Add(new MapPoint(0, 0));
points.Add(new MapPoint(1, 1));
polyline.Paths.Add(points);
// Serialize it
NetDataContractSerializer serializer = new NetDataContractSerializer();
using (System.IO.MemoryStream stm = new System.IO.MemoryStream())
{
serializer.Serialize(stm, polyline);
}
Produces this error:System.Runtime.Serialization.InvalidDataContractException occurred. Message=Type 'ESRI.ArcGIS.Client.Geometry.PointCollection' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute.It would be great to have full support for this in the final version. Thanks,--Ryan