I have a base class with a few properties:
// must include any derived classes here as known types or else they will throw errors on serialization
[KnownType(typeof(CollaborationEventMeasureDistance))]
[DataContract]
public partial class CollaborationEvent
{
public bool HasBeenTransported { get; set; }
public Guid MessageBoxGuid { get; set; }
public CollaborationEvent()
{
HasBeenTransported = false;
}
}
And a derived class with some properties of its own:
public class CollaborationEventMeasureDistance : CollaborationEvent
{
public Geometry Geometry { get; set; }
}
When I serialize the derived class, all of its properties are serialized, but the properties it inherits from the base class are not:
<CollaborationEvent i:type="CollaborationEventMeasureDistance">
<Geometry xmlns:d4p1="http://schemas.datacontract.org/2004/07/ESRI.ArcGIS.Client.Geometry"
i:type="d4p1:Polyline">
<d4p1:spatialReference>
<d4p1:wkid>26910</d4p1:wkid>
</d4p1:spatialReference>
<d4p1:paths>
<d4p1:points>
<d4p1:point>
<d4p1:spatialReference>
<d4p1:wkid>26910</d4p1:wkid>
</d4p1:spatialReference>
<d4p1:x>460892.23924271885</d4p1:x>
<d4p1:y>5367682.5572773879</d4p1:y>
</d4p1:point>
<d4p1:point>
<d4p1:spatialReference i:nil="true" />
<d4p1:x>461001.35841108358</d4p1:x>
<d4p1:y>5367648.5755294543</d4p1:y>
</d4p1:point>
</d4p1:points>
</d4p1:paths>
</Geometry>
</CollaborationEvent>
Can anyone point out what I am doing wrong?
I expect my XML to look more like:
<CollaborationEvent i:type="CollaborationEventMeasureDistance">
<HasBeenTransported>True</HasBeenTransported>
<MessageBoxGuid>blah</MessageBoxGuid>
<Geometry xmlns:d4p1="http://schemas.datacontract.org/2004/07/ESRI.ArcGIS.Client.Geometry"
i:type="d4p1:Polyline">
<d4p1:spatialReference>
<d4p1:wkid>26910</d4p1:wkid>
</d4p1:spatialReference>
<d4p1:paths>
<d4p1:points>
<d4p1:point>
<d4p1:spatialReference>
<d4p1:wkid>26910</d4p1:wkid>
</d4p1:spatialReference>
<d4p1:x>460892.23924271885</d4p1:x>
<d4p1:y>5367682.5572773879</d4p1:y>
</d4p1:point>
<d4p1:point>
<d4p1:spatialReference i:nil="true" />
<d4p1:x>461001.35841108358</d4p1:x>
<d4p1:y>5367648.5755294543</d4p1:y>
</d4p1:point>
</d4p1:points>
</d4p1:paths>
</Geometry>
</CollaborationEvent>
Thanks
Assuming your Geometry class is serializable, try something like this: