Good stuff Christoph.  Thanks for taking the time to share it with us.

The dotnet247  site  ( M. Chen) makes a very good point though :

"since TreeNode contains some reference/pointer to
other object (Next), it's not a good practise to serialize such a class
object."

First time I visited that site; seems well-organized.

Steve Holak
Senior Software Architect

Brokerage Concepts IS Dept.
610-491-4879

email:  [EMAIL PROTECTED]



                    Christoph
                    <ChristophDotNet@AUST        To:     [EMAIL PROTECTED]
                    IN.RR.COM>                   cc:
                    Sent by: dotnet              Subject:     Re: [DOTNET] Object 
serialization to string representation
                    discussion
                    <[EMAIL PROTECTED]
                    OP.COM>


                    05/21/2002 11:21 PM
                    Please respond to
                    dotnet discussion






Steve,

There is no requirement for a default constructor with the SoapFormatter,
only with the XmlSerializer.

I messed around a little bit more trying to serialize a class derived from
or containing a TreeNode and I get exceptions in both cases.
Then I tried a BinaryFormatter instead a SoapFormatter and everything
seemed
to work, which makes me think that this might be a bug in the
SoapFormatter.
You can probably work around this with a SerializationSurrogate for the
TreeNode. You have to develop a class to handle thede-/serializing
TreeNodes
through the ISerializationSurrogate interface. You register this class with
a SurrogateSelector, then you pass that SurrogateSelector to the
SoapFormatter constructor, like this:

SurrogateSelector selector = new SurrogateSelector();
selector.AddSurrogate( typeof( TreeNode),
    new StreamingContext( StreamingContextStates.All ),
    new SerializableSurrogate() );
SoapFormatter formatter = new SoapFormatter( selector, new
StreamingContext( StreamingContextStates.All ) );

The surrogate will be called whenever you are trying to serialize or
deserialize a TreeNode instance.

I also just stumbled over this thread [1] in Microsoft's csharp newsgroup,
which is dealing with the same problem.

HTH,

Christoph Schittko
Software Architect
Mshow - a division of InterCall

[1] http://dotnet247.com/247reference/msgs/6/31186.aspx

----- Original Message -----
From: "Steve Holak" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, May 21, 2002 1:42 PM
Subject: Re: [DOTNET] Object serialization to string representation


> IIRC, there is a requirement for a default parameterless public
contructor
> on the serializable class, in order for the Soap Formatter to serialize
it,
> but I may be incorrect.  I haven't looked at Treenode; and have you tried
>
>  :base()? (or the VB analog?)
>
>
> Steve Holak
> Senior Software Architect
>
> Brokerage Concepts IS Dept.
> 610-491-4879
>
> email:  [EMAIL PROTECTED]
>
>
>
>                     Christoph
>                     <ChristophDotNet@AUST        To:
[EMAIL PROTECTED]
>                     IN.RR.COM>                   cc:
>                     Sent by: dotnet              Subject:     Re:
[DOTNET]
Object serialization to string representation
>                     discussion
>                     <[EMAIL PROTECTED]
>                     OP.COM>
>
>
>                     05/21/2002 01:46 PM
>                     Please respond to
>                     dotnet discussion
>
>
>
>
>
>
> This usually means that your class implements the ISerializable
interface,
> but does not implement the required constructor of the format.
>
> Here's from the Framework docs:
> The ISerializable interface implies a constructor with the signature
> Constructor(SerializationInfo info, StreamingContext context). At
> deserialization time, the current constructor is called only after the
data
> in the SerializationInfo has been deserialized by the formatter. In
general
> this constructor should be protected if the class is not sealed
> (NotInheritable in Visual Basic) .
>
> I couldn't tell that this is the case from your code samples ...
>
> HTH,
> Christoph Schittko
> Software Architect
> Mshow - a division of InterCall
>
> ----- Original Message -----
> From: "franklin gray" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, May 21, 2002 12:25 PM
> Subject: Re: [DOTNET] Object serialization to string representation
>
>
> Any idea what this means?
>
> An unhandled exception of type
> 'System.Runtime.Serialization.SerializationException' occurred in
> mscorlib.dll
>
> Additional information: The constructor to deserialize an object of type
> SoapSerialization.Class2 was not found.
>
>
> I tried it 3 ways with an error but the 4th works.
>
> <Serializable()> Public Class Class2
>     Inherits TreeNode
>     Public Sub New()
>         MyBase.New("Blank")
>     End Sub
>     Public MyData As String
> End Class
>
> <Serializable()> Public Class Class2
>     Inherits TreeNode
>     Public Sub New()
>     End Sub
>     Public MyData As String
> End Class
>
> <Serializable()> Public Class Class2
>     Inherits TreeNode
>     Public MyData As String
> End Class
>
>
> This works though
> <Serializable()> Public Class Class2
>     Public MyData As String
> End Class
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to