Serializing inherited objects

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Mark Saccomandi (mark.saccomandi_at_a.team.nu)
Date: 09/08/04


Date: Wed, 8 Sep 2004 10:49:02 +0200

Hi,

I'm extending a serializable class I made. The new class adds some features
that cannot be serialized automatically, this means that I have to implement
the ISerializable interface for my new class. What happens is that I do
serialize what I have written within the GetObjectData method, but now I do
not get to automatically serialize the data from my parent class.
Is there a way to serialize automatically the properties from my parent
class and then to serialize manually only what I have added in the derived
class?

Here's a sample of the code:

[Serializable]

public class OperDataSocketIn : Operator, ISerializable

{

    [NonSerialized]

    private DataSocket dataSocketIn;

    ...

    private OperDataSocketIn( SerializationInfo info, StreamingContext
context)

    {

        dataSocketIn =new DataSocket();

        dataSocketIn.Url= info.GetString("Url");

    }

    void ISerializable.GetObjectData(SerializationInfo info,
StreamingContext context)

    {

        info.AddValue("Url", dataSocketIn.Url);

    }

    ...

}

Using this code after deserializing I get an object that has empty values
except for dataSocketIn.Url.

Thanks, Mark Saccomandi



Relevant Pages

  • Re: form serialization (Code Worth Recommending Project)
    ... Test for the existence of all features that were introduced after NN4 ... if there is a newer known browser that does not have the feature. ... Serialize form data in a format similar or identical to the ... // The 'select-one' case code is an optimization for ...
    (comp.lang.javascript)
  • Re: Unable to serialize the session state.
    ... > confused because Hashtable object is ISerializable, ... (Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, ... graph, HeaderinHeaders, __BinaryWriter serWriter, Boolean fCheck) +683 ... Unable to serialize the session state. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: C# vs VB.Net
    ... In VB.NET you have to ~remember to put in "namespace ... Also, in VB 6, you could have the IDE ... Status unknown - I haven't used the serialize features of dotNET. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Deserialize unknown object
    ... public void GetObjectData(SerializationInfo info, StreamingContext context) ... And then serialize it using a simple remoting formatter and put a breakpoint ... > Hi Sahil Malik, ... >> You can reach me thru my blog at ...
    (microsoft.public.dotnet.languages.csharp)
  • Unable to serialize the session state
    ... Unable to serialize the session state. ... Exception Details: System.Web.HttpException: Unable to serialize the ... obj, ISurrogateSelector surrogateSelector, StreamingContext context, ...
    (microsoft.public.dotnet.framework.aspnet)