Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How can I use serialize and Deserialize to realize Store Function when update code?

How can I use serialize and Deserialize to realize Store Function when update code?

Scheduled Pinned Locked Moved C#
questiontutorialannouncement
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    smallkubi
    wrote on last edited by
    #1

    When I finished serialize and Deserialize,and create a local file . But if i need update code, i create a new variable in SerializationInfo ,for example ,I declare a new variable "A" in code. But when i deserialize exist old local file, the exception warning is "can not find A", so Deserialize failed. How can i do if i want to ignore A when deserialize old files?

    L 1 Reply Last reply
    0
    • S smallkubi

      When I finished serialize and Deserialize,and create a local file . But if i need update code, i create a new variable in SerializationInfo ,for example ,I declare a new variable "A" in code. But when i deserialize exist old local file, the exception warning is "can not find A", so Deserialize failed. How can i do if i want to ignore A when deserialize old files?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      It depends how your deserialisation is working, but basically you need something in the file to tell you which version the contents were created with.

      S 1 Reply Last reply
      0
      • L Lost User

        It depends how your deserialisation is working, but basically you need something in the file to tell you which version the contents were created with.

        S Offline
        S Offline
        smallkubi
        wrote on last edited by
        #3

        how to do it? I don't know how to do....Could u send me an example?

        L 1 Reply Last reply
        0
        • S smallkubi

          how to do it? I don't know how to do....Could u send me an example?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Example of what? I have no idea what your code is doing or how you are managing your data. Just think about what you are trying to do. If you change the definition of a class after it is serialised, then the data will no longer match. So you need some way to use the previous definition to deserialise it. How you achieve this will depend a lot on the structure of your data and the associated classes.

          S 1 Reply Last reply
          0
          • L Lost User

            Example of what? I have no idea what your code is doing or how you are managing your data. Just think about what you are trying to do. If you change the definition of a class after it is serialised, then the data will no longer match. So you need some way to use the previous definition to deserialise it. How you achieve this will depend a lot on the structure of your data and the associated classes.

            S Offline
            S Offline
            smallkubi
            wrote on last edited by
            #5

            Yes, but i have no idea to achieve it...Could u help me? For example, Class A { int a=0; int b=0; } When i finished serialise class A and create a local file "Saved". When i update my Class A Class A { int a=0; int b=0; int c=0; } Then deserialise "Saved", it will throw exception ,how can i do it? I hope when i deserialize "Saved",it will ignore c.

            L 1 Reply Last reply
            0
            • S smallkubi

              Yes, but i have no idea to achieve it...Could u help me? For example, Class A { int a=0; int b=0; } When i finished serialise class A and create a local file "Saved". When i update my Class A Class A { int a=0; int b=0; int c=0; } Then deserialise "Saved", it will throw exception ,how can i do it? I hope when i deserialize "Saved",it will ignore c.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You cannot do it with the new class, because it does not match. You must deserialize into an instance of the old class and then copy the data to the new one. [edit] If the new version of your class is actually based on the original you may be able to do it that way using a cast. Should be easy to test. [/edit]

              S 1 Reply Last reply
              0
              • L Lost User

                You cannot do it with the new class, because it does not match. You must deserialize into an instance of the old class and then copy the data to the new one. [edit] If the new version of your class is actually based on the original you may be able to do it that way using a cast. Should be easy to test. [/edit]

                S Offline
                S Offline
                smallkubi
                wrote on last edited by
                #7

                Oh, actually, my Class is a form , i use serilized to store input data, like textbox or radiobutton data. When my project version update, maybe i will add some textbox or other controls in form class, so i will not deserilize old file, i don't know how to handle it. Please tell me a method to realize save function.

                L 1 Reply Last reply
                0
                • S smallkubi

                  Oh, actually, my Class is a form , i use serilized to store input data, like textbox or radiobutton data. When my project version update, maybe i will add some textbox or other controls in form class, so i will not deserilize old file, i don't know how to handle it. Please tell me a method to realize save function.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  You probably need to write a custom serialiser.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups