❔ BinaryFormatter.Serialize(Stream, object)' is obsolete, What do I use instead?
I'm learning serialization in C# but it says binary formatters are obsolete. what should i use?
6 Replies
You could use a Non Binary Seriaizer
at least thats what microsoft recommends: https://learn.microsoft.com/en-us/dotnet/core/compatibility/serialization/5.0/binaryformatter-serialization-obsolete#recommended-action
Breaking change: BinaryFormatter serialization methods are obsolete...
Learn about the .NET 5 breaking change in core .NET libraries where serialize and deserialize methods on BinaryFormatter, Formatter, and IFormatter are obsolete.
Binary serialization is dangerous
JSON would be best
Or if you insist on a binary format, Protobuf
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.Very specifically,
BinaryFormatter
serialization is dangerous. There's nothing about the "binary" part of it that makes it dangerous. It's absolutely possible to have safe binary formats (protobuf, as you suggested) - and it's absolutely possible to have dangerous text formats (NetDataContractSerializer, which is XML-based).
BinaryFormatter
absolutely has its problems, but it's not the "binary" part that makes it dangerous.
(And yes, I know I'm responding to this well after the fact - just commenting in case people find it while searching.)Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.