Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read files generated by obsolete BinaryFormatter #88316

Closed
panxn opened this issue Jul 3, 2023 · 11 comments
Closed

Read files generated by obsolete BinaryFormatter #88316

panxn opened this issue Jul 3, 2023 · 11 comments
Assignees
Labels
area-System.Formats.Nrbf binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration tracking-external-issue The issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly
Milestone

Comments

@panxn
Copy link

panxn commented Jul 3, 2023

Perhaps it's not a good issue, I just need some suggestions.

According to BinaryFormatter Obsoletion Strategy, using BinaryFormatter is error in .NET8, and totally removed in .NET9.

Our product is preparing for it, we plan to replace BinaryFormatter with Json/Xml, but the difficulty is backward compatibility, how to read old file format in new product.

Is there anyway else (except BinaryFormatter) to read/parse files generated by BinaryFormatter? I guess BinaryFormatter saves type info and data members into files, so is it possible to dump all these information into json structure?

Currently I'm trying to create a Migrator.exe that stays in fixed old .NET version (maybe .NET framework) so that BinaryFormatter can keep alive for longer time, however the dependency assemblies are not available, so I create a SerializationBinder to return fake types. I have to say this way is too difficult. That's why I want to ask here to look for a better way.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 3, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 3, 2023
@teo-tsirpanis
Copy link
Contributor

Item 4 in #29976 seems to be what you need. @GrabYourPitchforks any news on the safe BinaryFormatter deserializer?

@teo-tsirpanis teo-tsirpanis added area-System.Runtime and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jul 3, 2023
@ghost
Copy link

ghost commented Jul 3, 2023

Tagging subscribers to this area: @dotnet/area-system-runtime
See info in area-owners.md if you want to be subscribed.

Issue Details

Perhaps it's not a good issue, I just need some suggestions.

According to BinaryFormatter Obsoletion Strategy, using BinaryFormatter is error in .NET8, and totally removed in .NET9.

Our product is preparing for it, we plan to replace BinaryFormatter with Json/Xml, but the difficulty is backward compatibility, how to read old file format in new product.

Is there anyway else (except BinaryFormatter) to read/parse files generated by BinaryFormatter? I guess BinaryFormatter saves type info and data members into files, so is it possible to dump all these information into json structure?

Currently I'm trying to create a Migrator.exe that stays in fixed old .NET version (maybe .NET framework) so that BinaryFormatter can keep alive for longer time, however the dependency assemblies are not available, so I create a SerializationBinder to return fake types. I have to say this way is too difficult. That's why I want to ask here to look for a better way.

Author: panxn
Assignees: -
Labels:

area-System.Runtime, untriaged

Milestone: -

@JeremyKuhne
Copy link
Member

@panxn in WinForms I created BinaryFormattedObject for manual parsing of existing data. You're welcome to copy it under the MIT license. It can also serialize as well. The only record type it doesn't handle is multidimensional/jagged arrays, didn't need to do that yet so I haven't written it. :)

@GrabYourPitchforks
Copy link
Member

@teo-tsirpanis An officially supported package is indeed being discussed, but development of such a package hasn't been resourced. I don't really have any progress on it to share at this time.

If you wanted to take the WinForms code you're totally free to do so. However, it has not been threat modeled or security reviewed for any scenarios outside of WinForms-specific scenarios. You would need to perform your own analysis of it in the context of your own application.

@rickbrew
Copy link
Contributor

rickbrew commented Jul 29, 2023

This is also critical for Paint.NET -- it'd be nice to have, say, a nuget package that provides BinaryFormatter and all the serialization logic, but requires me to provide surrogate serializers for every type I need to handle (even if that means things like string and T[], I'll do it!). For both serialization and deserialization. Otherwise I can't move forward to whatever version of .NET eventually removes BinaryFormatter (8? 9?), as all .PDN image files (the native multi-layered Paint.NET image format) would become instantly unusable.

I'm planning on revving the .PDN format such that it won't rely on BF at all, and this is the way forward for me anyway so I can actually add new functionality (new layer types, blend modes, etc.), but I still need to support the legacy format that's been used for 20 years by lots and lots of folks.

@JeremyKuhne
Copy link
Member

@rickbrew I'm curious whether or not the BinaryFormattedObject mentioned above has the functionality you require. It's effectively a DOM for the NRBF format.

@panxn
Copy link
Author

panxn commented Aug 2, 2023

Hi @JeremyKuhne thanks for your advice. We have considered copy .NET code, it should work, just hard to maintenance for us.
Our team has started the plan to convert BF format to JSON via a standalone .NET framework app so that BF keeps available as long as .NET framework is under support.

@rickbrew
Copy link
Contributor

rickbrew commented Aug 2, 2023

@rickbrew I'm curious whether or not the BinaryFormattedObject mentioned above has the functionality you require. It's effectively a DOM for the NRBF format.

It might work, but I need deserialization and serialization. Otherwise I will not be able to support both the old and new file format versions simultaneously, which could make things quite difficult for some end-users. For example: several people working on project(s), sharing and collaborating on files, but not all of them have the new version of my app. Person 1 saves some images in the new format, but then Person 2 can't load the images at all because they haven't installed the new app version. Maybe they can't because they're in an office and their IT department hasn't deployed the new version, and maybe won't for some time. If I can still use BinaryFormatter and support the old file format version, then Person 1 can at least File -> Save As -> and choose "Legacy .PDN Format" in the file type dropdown.

@tannergooding
Copy link
Member

@GrabYourPitchforks does this need to stay open to track the areas being investigated you mentioned or can it be closed?

@ericstj ericstj added needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration and removed untriaged New issue has not been triaged by the area owner labels Aug 14, 2023
@ericstj ericstj added this to the Future milestone Aug 14, 2023
@GrabYourPitchforks
Copy link
Member

@tannergooding this is already being tracked by internal work items. Feel free to keep this open or close it depending on your own needs. I personally don't need this item to remain open.

@tannergooding tannergooding added the tracking-external-issue The issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly label Aug 24, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Sep 24, 2023
@jkotas jkotas added the binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it label May 29, 2024
@jkotas
Copy link
Member

jkotas commented May 29, 2024

API proposal: #102014

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Formats.Nrbf binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it needs-further-triage Issue has been initially triaged, but needs deeper consideration or reconsideration tracking-external-issue The issue is caused by external problem (e.g. OS) - nothing we can do to fix it directly
Projects
None yet
Development

No branches or pull requests

9 participants