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

Binaryformatter migration guide #41564

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

jeffhandley and others added 5 commits April 23, 2024 19:09
- remove the migration samples as we won't provide them (at least now)
- remove WPF and WinForms part as it will be provided in Preview 7
- clarify the public type requirement for Messagepack
- describe ArrayRecord and SZArrayRecord<T>
- describe the OOB package
Copy link
Member

@bartonjs bartonjs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of time for today


Moreover, WinForms and WPF may require some additional changes starting from .NET 9 Preview 7.

## Summary
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None of the bullets here seem strongly related to the rest of the content on this page, so they're not really a Summary.

Are they left over from there being different content here that moved elsewhere?

(Maybe the idea is that they are summarizing the rest of the content across all other pages, but it doesn't quite feel like that)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the idea is that they are summarizing the rest of the content across all other pages, but it doesn't quite feel like that

That was my intention.

* [DataContractSerializer](../../../fundamentals/runtime-libraries/system-runtime-serialization-datacontractserializer.md) is an XML serializer that **fully supports the serialization programming model that was used by the `BinaryFormatter`**. It requires the known types to be specified up-front (but most .NET collections and primitive types are on a default allow-list and don't need to be specified). **It's the serializer that requires the least amount of effort to migrate to**.
* [System.Text.Json](./../system-text-json/overview.md) is strict by default and avoids any guessing or interpretation on the caller's behalf, emphasizing deterministic behavior. The library is intentionally designed this way for performance and security. In contrary to `BinaryFormatter`, by default it serializes **only public properties**. To deserialize a `readonly` field or property, `[JsonConstructor]` attribute needs be used to indicate that given constructor should be used to set these. It supports serialization and deserialization of most built-in collections, but it does not support dictionaries where keys are not primitive types. It supports polymorphic type hierarchy serialization and deserialization, but it needs to be explicitly enabled. The same goes for preserving the references and handling circular references. The default behavior can be changed by writing custom converters.
* [MessagePack](https://github.com/MessagePack-CSharp/MessagePack-CSharp) provides a **highly efficient binary serialization format**, resulting in smaller message sizes compared to JSON and XML. It's **very performant** and ships with built-in support for LZ4 compression. It works best when all serializable public types and members are annotated with dedicated attributes. It does not serialize non-public types and members by default, but it can be customized. It supports readonly types and members, by trying to select the best matching constructor. The constructor can be selected in an explicit way by using the `[SerializationConstructor]` attribute.
* `NrbfDecoder` should be used for reading any `BinaryFormatter` payload that was either persisted before the migration or comes from an actor that can not be migrated (example: client app owned by a 3rd party). This new type can read any NRBF (.NET Remoting Binary Format) payload, but it's mandatory to know the list of types that could have been serialized. Otherwise, it's impossible to create and hydrate the serialized objects.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the mandatory type list and hydration comments... I didn't think NrbfDecoder had hydration of anything other than NRBF primitive values and arrays thereof?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants