How to Load a file which is saved using BinaryFormatter.

Karkuvel Rajan Shanmugavel 20 Reputation points
2024-06-20T10:37:56.68+00:00

In our Control, we have used BinaryFormatter serialization to Save and Load. But in Net 9 BinaryFormatter is completely removed. Due to that, we are planned to write our Serialization logic using DataContractSerialization.

But we need to deserialize the old files which are saved using BinaryFormatter. Is there any easy way to read those files?

We have used many Classes in our Control and Serialized all of them. Our Structure is basically like this.

Serializable Class ---> Properties of Custom Class Types ---> Properties of Custom Class Types ---> Properties with basic DataTypes.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,903 questions
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
5,500 questions
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 46,466 Reputation points Microsoft Vendor
    2024-06-21T09:45:11.5033333+00:00

    Hi @Karkuvel Rajan Shanmugavel , Welcome to Microsoft Q&A,

    The simpler approach is to create a compatibility item in the older .NET version to handle the conversion from BinaryFormatter to DataContractSerializer. Deserialize the BinaryFormatter data and reserialize it using DataContractSerializer. Then you can use the converted file in .NET 9.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.