StateManagedCollection throw stackOverfolow exception.http://forums.asp.net/t/1641765.aspx/1?StateManagedCollection+throw+stackOverfolow+exception+Wed, 12 Jan 2011 10:32:45 -050016417654250137http://forums.asp.net/p/1641765/4250137.aspx/1?StateManagedCollection+throw+stackOverfolow+exception+StateManagedCollection throw stackOverfolow exception. <table width="425" height="84"> <tbody> <tr> <td class="votecell"><br> </td> <td class="postcell">&lt;div&gt; &lt;div class=&quot;post-text&quot;&gt; <p>Hello</p> <p>I have a problem with StateManagedCollection when i try to make it generic. This is the code:</p> <p><br> </p> <p><pre class="prettyprint">[ AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) ] public abstract class GenericCollection&lt;T&gt; : StateManagedCollection { private static readonly Type[] _knownTypes; private int capacity; static GenericCollection() { GenericCollection&lt; T&gt;._knownTypes = new Type[] { typeof(T) }; } public GenericCollection(){} public int Add(T item) { return ((IList)this).Add(item); } public bool Contains(T item) { return ((IList)this).Contains(item); } public void CopyTo(T[] array, int index) { this.CopyTo(array, index); } protected abstract override object CreateKnownType(int index); protected override Type[] GetKnownTypes() { return BaseItemCollection&lt;T&gt;._knownTypes; } public int IndexOf(T value) { return ((IList)this).IndexOf(value); } public void Insert(int index, T item) { ((IList)this).Insert(index, item); } protected override void OnClear() { base.OnClear(); } protected override void OnRemoveComplete(int index, object value) { base.OnRemoveComplete(index, value); } protected override void OnValidate(object value) { base.OnValidate(value); } public void Remove(T item) { this.Remove(item); } public void RemoveAt(int index) { this.RemoveAt(index); } public int Capacity { get { return this.capacity; } set { this.capacity = value; } } public T this[int i] { //HERE THROW STACKOVERFLOW EXCEPTION get { return (T)this[i]; } set { this[i] = value; } } }</pre><br> </p><p>This is the collection that i try to make it generic</p><p><br></p><p><pre class="prettyprint">[ AspNetHostingPermission(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal), AspNetHostingPermission(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal) ] public sealed class ItemCollection : GenericCollection&lt;Item&gt; { protected override object CreateKnownType(int index) { return new Item(); } protected override void SetDirtyObject(object o) { if (o is Item) { ((Item)o).SetDirty(); } } } </pre><br> This is the Item that i try to put:</p><p><br></p><p><pre class="prettyprint"> [ Browsable(false), TemplateInstance(TemplateInstance.Single), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), PersistenceMode(PersistenceMode.InnerProperty) ] public ITemplate Template { get { return _temlpate; } set { _temlpate = value; } } [ Category("Behavior"), DefaultValue(""), Description(""), NotifyParentProperty(true), ] public string Name { get { object animation = ViewState["Name"]; return (animation == null) ? string.Empty : (string)animation; } set { ViewState["Name"] = value; } } } </pre><br> <br> </p> &lt;/div&gt;&lt;/div&gt;</td> </tr> </tbody> </table> 2011-01-12T10:32:45-05:00