Ошибка десериализации XML при неявном приведении типов
Помогите найти причину ошибки.
Есть класс точки в который включено неявное приведение в другие типы точек (один из математической библиотеки, два других из AutoCAD)
public class Point : ICloneable
{
public string Id;
public string Name { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
public Point()
{
Id = string.Empty;
Name = string.Empty;
X = 0;
Y = 0;
Z = 0;
}
public Point(double X, double Y, double Z)
{
Id = string.Empty;
Name = string.Empty;
this.X = X;
this.Y = Y;
this.Z = Z;
}
public static implicit operator Point3d(Point point)
{
return new Point3d(point.X, point.Y, point.Z);
}
public static implicit operator PolylineVertex3d(Point point)
{
return new PolylineVertex3d(point);
}
public static implicit operator MathPoint(Point point)
{
return new MathPoint(point.X, point.Y, point.Z);
}
public object Clone()
{
return MemberwiseClone();
}
}
Есть класс в котором происходит собственно сериализация/десериализация.
public class Section
{
public Section()
{
Wells = new List<Well>();
}
public Section(List<Well> Wells)
{
this.Wells = Wells;
}
public List<Well> Wells { get; set; }
public string HorizontalScale { get; set; }
public string VerticalScale { get; set; }
public static Section LoadSection(string path)
{
try
{
using (StreamReader fs = new StreamReader(path, Encoding.GetEncoding(1251)))
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Section));
xmlSerializer.UnknownElement += (sender, e) =>
{
var sec = (Well)e.ObjectBeingDeserialized;
if (e.Element.Name == "WellHeight")
{
sec.WellHeadPoint.Z = double.Parse(e.Element.InnerText);
}
};
return (Section)xmlSerializer.Deserialize(fs);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return new Section();
}
}
public void SaveSection(string path)
{
using (FileStream fs = new FileStream(path, FileMode.Create))
{
using (StreamWriter writer = new StreamWriter(fs, Encoding.GetEncoding(1251)))
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Section));
xmlSerializer.Serialize(writer, this);
}
}
}
}
Section содержит Well, Well содержит Point.
При попытке десериализовать объект пока в классе Point есть неявное приведение выбрасывается ошибка "невозможно создать временный класс (результат=1). CS0012 тип тип определен в сборке ссылка на которую отсутствует". При этом все ссылки есть и в остальной части программы работают.
Полазив по интернету не нашел ничего по теме, чего-то точно не вижу, тыканье носом приветствуется.
Ответы (1 шт):
public static Section LoadSection(string path)
{
try
{
using (StreamReader fs = new StreamReader(path, Encoding.GetEncoding(1251)))
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Section),new Type[] {typeof(MathPoint), typeof(Point3d), typeof(PolylineVertex3d)});
xmlSerializer.UnknownElement += (sender, e) =>
{
var sec = (Well)e.ObjectBeingDeserialized;
if (e.Element.Name == "WellHeight")
{
sec.WellHeadPoint.Z = double.Parse(e.Element.InnerText);
}
};
return (Section)xmlSerializer.Deserialize(fs);
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return new Section();
}
}
Вот так просто всё и решается, ещё раз спасибо Alexander Petrov