有沒有其他人遇到過這個問題?我有一個方法,在泛型類中調用帶有委託的泛型方法。我已經將該類標記爲可序列化,並且它沒有任何抱怨地進行序列化。但是,當我試圖反序列化這個類的一個對象時,它會掛住CPU並掛起機器。在通用類中調用泛型方法的委託在反序列化過程中固定CPU
代碼示例:
public delegate T CombinationFunctionDelegate<T,U,V>(U a, V b);
[Serializable]
public class SDictionary<TKey, TValue> : Dictionary<TKey, TValue>
{
public SDictionary()
: base()
{
}
protected SDictionary(SerializationInfo info, StreamingContext context)
: base(info, context)
{}
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
public List<ListItem> ToListItems()
{
return Convert(delegate(TKey key, TValue value)
{
return new ListItem(key.ToString(), value.ToString());
});
}
public List<U> Convert<U>(CombinationFunctionDelegate<U, TKey, TValue> converterFunction)
{
List<U> res = new List<U>();
foreach (TKey key in Keys)
res.Add(converterFunction(key, this[key]));
return res;
}
}
我可以把一個實例該類到ViewState中(例如)就好了,但是當我再次嘗試提取ViewState的對象,在機器尖峯CPU和反序列化調用永遠不會返回(即無限循環)。
當我刪除ToListItems()方法時,一切都很好用。這真的很奇怪,還是我不明白序列化? =)
嘿感謝的想法。我編輯我的帖子,以顯示該類的更簡單的版本,提供相同的問題,包括您的建議。我仍然認爲它真的很奇怪=) – Badjer 2008-11-07 00:25:30