Note that there are some explanatory texts on larger screens.

plurals
  1. PODelegate calling generic method inside of a generic class pegs CPU during deserialization
    primarykey
    data
    text
    <p>Has anyone else run into this problem before? I've got a method that calls a generic method with a delegate, inside of a generic class. I've marked the class as Serializable, and it serializes without complaint. But, when I try to deserialize an object of this class, it pegs the CPU and hangs the machine.</p> <p>Code example:</p> <pre><code>public delegate T CombinationFunctionDelegate&lt;T,U,V&gt;(U a, V b); [Serializable] public class SDictionary&lt;TKey, TValue&gt; : Dictionary&lt;TKey, TValue&gt; { 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&lt;ListItem&gt; ToListItems() { return Convert(delegate(TKey key, TValue value) { return new ListItem(key.ToString(), value.ToString()); }); } public List&lt;U&gt; Convert&lt;U&gt;(CombinationFunctionDelegate&lt;U, TKey, TValue&gt; converterFunction) { List&lt;U&gt; res = new List&lt;U&gt;(); foreach (TKey key in Keys) res.Add(converterFunction(key, this[key])); return res; } } </code></pre> <p>I can put an instance of this class into ViewState (for example) just fine, but when I try to extract the object from ViewState again, the CPU on the machine spikes and the deserialization call never returns (ie, infinite loop).</p> <p>When I remove the ToListItems() method, everything works wonderfully. Is this really weird, or do I just not understand serialization? =)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload