Serialize a class Inheriting from an ISerializable ClassHi,<br><br>I want to serialize my custom class derived from Windows Forms TreeNode. TreeNode already Implements the ISerealizable interface<br><br>I already tried 2 solutions but didnt wok :<br><br>1) Override Serialize and Deserialize methods : didint work I got this exception The constructor to deserialize an object of type 'ConsoleApplication1.MyTreeNode' was not found. I dont know how to deserialize my Nodes back by defining this constructor. Then why the method Deserialize id not Called ? (I tested with a breakpoint) .this is my code<br><div style="margin: 5px 20px 20px;"> <div class="smallfont" style="margin-bottom: 2px;">Code :</div> <pre class="alt2" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 330px;"><div dir="ltr" style="text-align: left;">&lt;Serializable()&gt; Public Class MyTreeNode<br> Inherits TreeNode<br><br> Public m_id As Integer<br><br> Public Sub New()<br> End Sub<br><br> Public Sub New(ByVal id As Integer)<br> m_id = id<br> End Sub<br><br> Protected Overrides Sub Serialize(ByVal si As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)<br> MyBase.Serialize(si, context)<br> si.AddValue("id", m_id)<br> End Sub<br><br> Protected Overrides Sub Deserialize(ByVal serializationInfo As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)<br> MyBase.Deserialize(serializationInfo, context)<br> m_id = DirectCast(serializationInfo.GetValue("id", GetType(Integer)), Integer)<br> End Sub<br><br>End Class</div></pre> </div>2)Implementing ISerializable again and build the Serialization from scratch : this Solution is working well but got Exceptions when working with a Hierarchical TreeNode . this is my code :<br><br><div style="margin: 5px 20px 20px;"> <div class="smallfont" style="margin-bottom: 2px;">Code :</div> <pre class="alt2" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 370px;"><div dir="ltr" style="text-align: left;">&lt;Serializable()&gt; Public Class MyTreeNode<br> Inherits TreeNode<br> Implements ISerializable<br><br> Public m_id As Integer<br><br> Public Sub New()<br><br> End Sub<br><br> Public Sub New(ByVal id As Integer)<br> m_id=id<br> End Sub<br><br> Protected Sub New(ByVal si As SerializationInfo, ByVal context As StreamingContext)<br> Dim j As Integer = 1<br> m_id = CType(si.GetValue("id", GetType(Integer)), Integer)<br> Dim o As Object<br> Dim i As Integer = 1<br> While i &lt;= (si.MemberCount - j)<br> o = si.GetValue(i.ToString, GetType(Object))<br> Nodes.Add(CType(o, TreeNode))<br> i += 1<br> End While<br> End Sub<br><br> Public Overridable Sub GetObjectData(ByVal si As SerializationInfo, ByVal context As StreamingContext)<br> si.AddValue("id", m_id)<br> Dim i As Integer = 1<br> For Each o As Object In Nodes<br> If o IsNot Nothing Then<br> si.AddValue(i.ToString, o)<br> i += 1<br> End If<br> Next<br> End Sub<br>End Class</div></pre> </div>Well, hope that I'll fix my issue from your answers . Thanks In Advance.<br>© 2009 Microsoft Corporation. All rights reserved.Thu, 19 Jun 2008 00:15:52 Z3dd83c1e-d2bb-48f9-b03b-9b9789702c2ehttp://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/3dd83c1e-d2bb-48f9-b03b-9b9789702c2e#3dd83c1e-d2bb-48f9-b03b-9b9789702c2ehttp://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/3dd83c1e-d2bb-48f9-b03b-9b9789702c2e#3dd83c1e-d2bb-48f9-b03b-9b9789702c2eMazzicahttp://social.msdn.microsoft.com/Profile/en-US/?user=MazzicaSerialize a class Inheriting from an ISerializable ClassHi,<br><br>I want to serialize my custom class derived from Windows Forms TreeNode. TreeNode already Implements the ISerealizable interface<br><br>I already tried 2 solutions but didnt wok :<br><br>1) Override Serialize and Deserialize methods : didint work I got this exception The constructor to deserialize an object of type 'ConsoleApplication1.MyTreeNode' was not found. I dont know how to deserialize my Nodes back by defining this constructor. Then why the method Deserialize id not Called ? (I tested with a breakpoint) .this is my code<br><div style="margin: 5px 20px 20px;"> <div class="smallfont" style="margin-bottom: 2px;">Code :</div> <pre class="alt2" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 330px;"><div dir="ltr" style="text-align: left;">&lt;Serializable()&gt; Public Class MyTreeNode<br> Inherits TreeNode<br><br> Public m_id As Integer<br><br> Public Sub New()<br> End Sub<br><br> Public Sub New(ByVal id As Integer)<br> m_id = id<br> End Sub<br><br> Protected Overrides Sub Serialize(ByVal si As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)<br> MyBase.Serialize(si, context)<br> si.AddValue("id", m_id)<br> End Sub<br><br> Protected Overrides Sub Deserialize(ByVal serializationInfo As System.Runtime.Serialization.SerializationInfo, ByVal context As System.Runtime.Serialization.StreamingContext)<br> MyBase.Deserialize(serializationInfo, context)<br> m_id = DirectCast(serializationInfo.GetValue("id", GetType(Integer)), Integer)<br> End Sub<br><br>End Class</div></pre> </div>2)Implementing ISerializable again and build the Serialization from scratch : this Solution is working well but got Exceptions when working with a Hierarchical TreeNode . this is my code :<br><br><div style="margin: 5px 20px 20px;"> <div class="smallfont" style="margin-bottom: 2px;">Code :</div> <pre class="alt2" style="border: 1px inset ; margin: 0px; padding: 6px; overflow: auto; width: 640px; height: 370px;"><div dir="ltr" style="text-align: left;">&lt;Serializable()&gt; Public Class MyTreeNode<br> Inherits TreeNode<br> Implements ISerializable<br><br> Public m_id As Integer<br><br> Public Sub New()<br><br> End Sub<br><br> Public Sub New(ByVal id As Integer)<br> m_id=id<br> End Sub<br><br> Protected Sub New(ByVal si As SerializationInfo, ByVal context As StreamingContext)<br> Dim j As Integer = 1<br> m_id = CType(si.GetValue("id", GetType(Integer)), Integer)<br> Dim o As Object<br> Dim i As Integer = 1<br> While i &lt;= (si.MemberCount - j)<br> o = si.GetValue(i.ToString, GetType(Object))<br> Nodes.Add(CType(o, TreeNode))<br> i += 1<br> End While<br> End Sub<br><br> Public Overridable Sub GetObjectData(ByVal si As SerializationInfo, ByVal context As StreamingContext)<br> si.AddValue("id", m_id)<br> Dim i As Integer = 1<br> For Each o As Object In Nodes<br> If o IsNot Nothing Then<br> si.AddValue(i.ToString, o)<br> i += 1<br> End If<br> Next<br> End Sub<br>End Class</div></pre> </div>Well, hope that I'll fix my issue from your answers . Thanks In Advance.<br>Fri, 29 Sep 2006 10:10:09 Z2006-09-29T10:10:09Zhttp://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/3dd83c1e-d2bb-48f9-b03b-9b9789702c2e#e2447c96-fce1-43de-a78c-49d807082c2chttp://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/3dd83c1e-d2bb-48f9-b03b-9b9789702c2e#e2447c96-fce1-43de-a78c-49d807082c2cLucian Bargaoanuhttp://social.msdn.microsoft.com/Profile/en-US/?user=Lucian%20BargaoanuSerialize a class Inheriting from an ISerializable Class<P>For no 1 add a constructor like</P> <P>Protected Sub New(ByVal si As SerializationInfo, ByVal context As StreamingContext)<BR></P> <P>and call the base constructor with those parameters.</P>Fri, 29 Sep 2006 11:52:50 Z2006-09-29T11:52:50Z