Hi I have the following classes :
public class Point2D
{
public Point2D()
{
X = double.NaN;
Y = double.NaN;
}
public Point2D(double xValue, double yValue)
{
X = xValue;
Y = yValue;
}
/// <summary>
/// The X coordinate of the point.
/// </summary>
public double X { get; set; }
/// <summary>
/// The Y coordiante of the point.
/// </summary>
public double Y { get; set; }
}
public class CameraCalibration2D
{
private Point2D _GridOffset = new Point2D(0, 0);
[Category("Grid Definition")]
[Description("The location of the top left corner of the calibration grid in real world coordinates (mm).")]
[DisplayName("Grid Offset")]
public Point2D GridOffset
{
get { return _GridOffset; }
set { _GridOffset = value; }
}
}
public class LaserLineProfiler
{
public LaserLineProfiler()
{
}
#region Configuration
private CameraCalibration2D _Calibration2D = new CameraCalibration2D();
[Category("Calibration")]
[Description("The real world to pixel mapping calibration.")]
[DisplayName("2D Calibration")]
public CameraCalibration2D Calibration2D
{
get { return _Calibration2D; }
set { _Calibration2D = value; }
}
private Point2D _Scale = new Point2D(0, 0);
//[IgnoreDataMember]
[Category("Laser Line")]
[Description("The length, in world units, of one pixel, in the X and Y-direction")]
public Point2D Scale
{
get{return _Scale;}
set{_Scale = value;}
}
public partial class PageDeviceEditor : UserControl
{
LaserLineProfiler m_CaptureDevice = new LaserLineProfiler() ;
public PageDeviceEditor()
{
InitializeComponent();
}
private void buttonAddDevice_Click(object sender, EventArgs e)
{
propertyGridDeviceConfig.SelectedObject = m_CaptureDevice
}
private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine(SerializeCalDataObject.ToXML(m_CaptureDevice));
}
}
public static class SerializeCalDataObject
{
public static XElement ToXML(this object o)
{
Type t = o.GetType();
DataContractSerializer serializer = new DataContractSerializer(t);
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
serializer.WriteObject(xw, o);
return XElement.Parse(sw.ToString());
}
}
When I try to serialize the object I get the following error
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in System.Runtime.Serialization.dll
Additional information: The use of type 'Utils.Point2D' as a get-only collection is not supported with NetDataContractSerializer. Consider marking the type with the CollectionDataContractAttribute attribute or the SerializableAttribute attribute or adding a setter to the property.
This is only occur when I take off [IgnoreDataMember] for the Property Scale in the laserLineProfiler, and it does not occur when I use the same Point2d inside the class CameraCalibration2D where CameraCalibration2D object is a property of LaserLineProfiler class it does not complain any reason why I'm getting this error.
Thanks