According to Microsoft, BinaryFormatter
deserializes data in an insecure manner and using it is "equivalent of interpreting the payload as a standalone executable and launching it". It is therefore recommended that you switch to preferred alternatives that can handle untrusted data safely such as XmlSerializer
, DataContractSerializer
, BinaryReader
, BinaryWriter
, or System.Text.Json
.