Serialization missing data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mdb

    Serialization missing data

    I have a class (very simple int type data, as shown below) that I have
    serialized to disk. In my next version of the program, I have added some
    variables to that class. I'm expecting that this will break the
    serialization when I try to load the object from disk.

    I know there is something in .NET 2.0 to handle this, but how can I do it
    with .NET 1.1? Some sample code would be much appreciated...

    // The old version
    class Data
    {
    int x;
    int y;
    }

    // The new version
    class Data
    {
    int x;
    int y;
    int z;
    }

    --
    -mdb
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Serialization missing data

    mdb,

    In .NET 1.1, you will have to implement the ISerializable interface, as
    well as implement the special serialization constructor. This will allow
    you to query the serialization store (passed into the serialization
    constructor) to see if a value exists. Then, you can selectively assign
    values as you see fit.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "mdb" <m_b_r_a_y@c_t_ i_u_s_a__d0t__c om> wrote in message
    news:Xns96689DF 92825Bmbrayctiu sacom@207.46.24 8.16...[color=blue]
    >I have a class (very simple int type data, as shown below) that I have
    > serialized to disk. In my next version of the program, I have added some
    > variables to that class. I'm expecting that this will break the
    > serialization when I try to load the object from disk.
    >
    > I know there is something in .NET 2.0 to handle this, but how can I do it
    > with .NET 1.1? Some sample code would be much appreciated...
    >
    > // The old version
    > class Data
    > {
    > int x;
    > int y;
    > }
    >
    > // The new version
    > class Data
    > {
    > int x;
    > int y;
    > int z;
    > }
    >
    > --
    > -mdb[/color]


    Comment

    • mdb

      #3
      Re: Serialization missing data

      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
      in news:OpuatcuZFH A.3152@TK2MSFTN GP14.phx.gbl:
      [color=blue]
      > In .NET 1.1, you will have to implement the ISerializable
      > interface, as
      > well as implement the special serialization constructor. This will
      > allow you to query the serialization store (passed into the
      > serialization constructor) to see if a value exists. Then, you can
      > selectively assign values as you see fit.[/color]

      It does help... I guess I would need to explicitly deserialize ALL of the
      class members? How would I know the keys to use for GetValue(...), or how
      would I know what key belongs to what variable? Are the keys named the
      same as the variable name? (Remember that I'm trying to prevent my app
      from breaking, and I was using default serialization prior).

      I guess this means that I would have manually serialize/deserialize for all
      future versions as well?

      --
      -mdb

      Comment

      • Fred Mellender

        #4
        Re: Serialization missing data

        This is similar to another thread ("New versions vs. serialization") , which
        might (might not) be of help:



        "mdb" <m_b_r_a_y@c_t_ i_u_s_a__d0t__c om> wrote in message
        news:Xns966A836 75ACF3mbrayctiu sacom@207.46.24 8.16...[color=blue]
        > "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote
        > in news:OpuatcuZFH A.3152@TK2MSFTN GP14.phx.gbl:
        >[color=green]
        >> In .NET 1.1, you will have to implement the ISerializable
        >> interface, as
        >> well as implement the special serialization constructor. This will
        >> allow you to query the serialization store (passed into the
        >> serialization constructor) to see if a value exists. Then, you can
        >> selectively assign values as you see fit.[/color]
        >
        > It does help... I guess I would need to explicitly deserialize ALL of
        > the
        > class members? How would I know the keys to use for GetValue(...), or how
        > would I know what key belongs to what variable? Are the keys named the
        > same as the variable name? (Remember that I'm trying to prevent my app
        > from breaking, and I was using default serialization prior).
        >
        > I guess this means that I would have manually serialize/deserialize for
        > all
        > future versions as well?
        >
        > --
        > -mdb[/color]


        Comment

        • mdb

          #5
          Re: Serialization missing data

          "Fred Mellender" <nospamPlease_f redm@frontierne t.net> wrote in
          news:Be0oe.80$t y2.14@news02.ro c.ny:
          [color=blue]
          > This is similar to another thread ("New versions vs. serialization") ,
          > which might (might not) be of help:
          >[/color]

          yeah I use the dictionary technique in other code, when I want to save a
          configuration and such, but i don't think its that useful here. The
          classes that I am serializing are being used for remoting. And while
          there's no reason why a dictionary *wouldn't* work in theory, in this case,
          i'm trying to make sure that an EXISTING application won't break - not that
          the code I'm developing will be extendable in the future. Not only that
          but its more of a kludge in this circumstance.

          I just wish M$ would release .NET 2.0 already - they've included attributes
          to help with this issue.

          --
          -mdb

          Comment

          Working...