Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6615885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:31:01+00:00 2026-05-25T20:31:01+00:00

I have to work an an old application that used binaryFormatter to serialize application

  • 0

I have to work an an old application that used binaryFormatter to serialize application data into filestream (say in a file named “data.oldformat”)
without any optimizazion the main class has been marked with attribute

<serializable()>public MainClass
....... 
end class

and the serialization code

dim b as new binaryformatter
b.serialize(mystream,mymainclass)

In an attempt to optimize the serialization/deserialization process I simply made the class implement the ISerializable interface and wrote some optimized serialization routines

<serializable()>public MainClass
       implements ISerializable
....... 
end class

The optimization works really well but I MUST find a way to reatrive the data inside the old files for backward compatibility.

How can I do that??

Pierluigi

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:31:01+00:00Added an answer on May 25, 2026 at 8:31 pm

    stmax has an excellent answer, however I would implement it like this, which uses SerializationEntry.GetEnumerator() instead of try/catch. This way is cleaner and significantly faster.

    public MainClass(SerializationInfo info, StreamingContext context) {
        int version = 0;
        foreach (SerializationEntry s in info)
        {
            if (s.Name == "version") 
            {
                version = (int)s.Value;
                break;
            }
        }
    
        switch (version) {
          case 0:
            // deserialize "old format"
            break;
          case 1:
            // deserialize "new format, version 1"
            break;
          default:
            throw new NotSupportedException("version " + version + " is not supported.");
        }
    }
    

    I would prefer a LINQ version using .FirstOrDefault(), but SerializationInfo does not implement IEnumerable – in face, weirdly enough, it doesn’t even implement the old IEnumerable interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a task at work that involves converting legacy SGM files into XML.
We are porting an old application that used a hierarchical database to a relational
I have an application that requires some work on image filters, so I just
I have to work on an old 1.3 JVM and I'm asked to create
At work I have an app sitting on Oracle 7.3 (old stuff, yes). Recently
I have to update old projects at work. I do not have any experience
At the team with which I work, we have an old codebase using PHP's
I have to work on some code that's using generic lists to store a
I have to work with an API that uses a lot of by-reference parameters.
I have to work with a queryset, that is already filtered, eg. qs =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.