PDA

View Full Version : سوال: خطا در زمان Serialize کردن یک کلاس از نوع DataContract



arman_Delta2002
دوشنبه 09 مرداد 1396, 18:46 عصر
سلام خطا زیر رو میده!
کلاس سریالایز میشه ولی زمان دیسریالایز کردن این خطا رو میده علت چیه ؟!
کد سریالایز و دی سریالایز درست کار میکنه


Error in line 1 position 248. Element 'http://schemas.datacontract.org/2004/07/UISideQuickFilter.QFilter:QFilter' contains data from a type that maps to the name 'http://schemas.datacontract.org/2004/07/UISideQuickFilter.QSelect:QSelect1'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver if you are using DataContractSerializer or add the type corresponding to 'QSelect1' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to the serializer.


کلاس ایجاد شده



[DataContract]
[KnownType(typeof(QSelect1))]
public class QSelect1 : QFilter.QFilter
{
#region Property
[DataMember]
private readonly string _fieldName;
[DataMember]
private readonly string _currentRowID; //ای دی رکورد جاری
[DataMember]
private readonly string _rowsCount;// چند رکورد قبل را نمایش دهد
#endregion
//-1 به معنی دریافت تمام رکورد ها میباشد
public QSelect1(string culmnName, string CurrentRowID, string RowsCount ="20")
: base(culmnName)
{
_fieldName = culmnName;
_currentRowID = CurrentRowID;
_rowsCount = RowsCount;
}

public override string ToString()
{
return _fieldName + " OFFSET " + _currentRowID + " Rows Fetch Next " + _rowsCount + " Rows ONLY ";
}
}

arman_Delta2002
دوشنبه 09 مرداد 1396, 19:29 عصر
پاسخ رو پیدا کردم بالای کلاس QFilter باید نوع [KnownType(typeof(QSelect1))] رو هم مینوشتم تا بشناسه