Results 1 to 4 of 4

Thread: Serialization Question

  1. #1

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    Serialization Question

    I spend my spare time trying to create a football game in VB.NET. I have a save game file saved using serialization which I am using to test code. This file contains all the elements of gameplay (stored plays, games, options, etc...) I create this file in the software itself using the code I created; I put a lot of work into this save game file and I would like to continue using it.

    However, I discovered I need to add a couple member variables to the class from which the saved object is derived (object is called m_League, class is ClLeague). Any time I've altered ClLeague my old saved games don't load anymore because the new m_League object does not match the old m_League object. I have to start a new game and create m_League from scratch which wastes a lot of time.

    This must pop up in with the professionals out there who write patches for software and need the users old saved files to continue working. Is there any trick to this situation or do I have to just accept it?

    Thanks!
    Intermediate Level Programmer Extraordinaire

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Serialization Question

    I'm assuming you are using Binary Serialization. Use XML Serialization instead, which is usually not affected by the changes to the class (unless of course a lot has changed to make that information unusable)
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,109

    Re: Serialization Question

    There would be a weird workaround, which would be to make a converter. You would have to retain the old class and the new class as two separate things with a method to convert one to the other. You would then deserialize the old class, run the method, then serialize the new class. This would require more discipline than anything else. If your class was in a dll, it probably wouldn't be particularly difficult, but it would be a pain if you had it in the main program.

    PS: While XML serialization might solve the problem, it isn't exactly a replacement. If you use that, you have to accept the XML nature of the data, which means files that are easily read and altered by anybody unless you encrypt them, and they will be relatively HUGE. Furthermore, I seem to remember that there were some real limitations to XML serialization, though I don't remember what they were. Some types of collections wouldn't serialize correctly.
    My usual boring signature: Nothing

  4. #4

    Thread Starter
    Hyperactive Member neef's Avatar
    Join Date
    Dec 2001
    Location
    Boston
    Posts
    311

    Re: Serialization Question

    Very clever "converter" idea!. I'll have to think about what's better: just to spend time recreating stuff in my game or making a better long term solution by trying your idea.

    Also, XML serialization is not the answer for my situation for the reasons you stated Shaggy Hiker.

    Thank you both for your ideas. I'll let this thread run another day and then mark it Solved.
    Intermediate Level Programmer Extraordinaire

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width