|
| 1 | +--- |
| 2 | +title: "Breaking change: In-box BinaryFormatter implementation removed and always throws" |
| 3 | +description: Learn about the .NET 9 breaking change in serialization where the in-box BinaryFormatter implementation was removed and always throws exceptions. |
| 4 | +ms.date: 08/06/2024 |
| 5 | +--- |
| 6 | +# In-box BinaryFormatter implementation removed and always throws |
| 7 | + |
| 8 | +The "in box" <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter> implementation now throws exceptions at run time in all cases. This is the final stage of the [BinaryFormatter obsoletion plan](https://github.com/dotnet/designs/blob/main/accepted/2020/better-obsoletion/binaryformatter-obsoletion.md). |
| 9 | + |
| 10 | +## Previous behavior |
| 11 | + |
| 12 | +You could construct a <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter> instance and use it to serialize and deserialize payloads. |
| 13 | + |
| 14 | +## New behavior |
| 15 | + |
| 16 | +Starting in .NET 9, the in-box <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter> implementation throws exceptions on use, even with the settings that previously enabled its use. Those settings are also removed. |
| 17 | + |
| 18 | +## Version introduced |
| 19 | + |
| 20 | +.NET 9 Preview 6 |
| 21 | + |
| 22 | +## Type of breaking change |
| 23 | + |
| 24 | +This change is a [behavioral change](../../categories.md#behavioral-change). |
| 25 | + |
| 26 | +## Reason for change |
| 27 | + |
| 28 | +`BinaryFormatter` is an insecure format and the cause of many security bugs. Removing it from the framework increases the overall safety of .NET. |
| 29 | + |
| 30 | +## Recommended action |
| 31 | + |
| 32 | +If your code uses `BinaryFormatter`, you should select a new serialization format and migrate your code. |
| 33 | + |
| 34 | +If you judge the risk of `BinaryFormatter` acceptable for your use cases and you're committed to using a class that can't be made secure, you'll still be able to use `BinaryFormatter` through a separate, unsupported NuGet package. |
| 35 | + |
| 36 | +For more information, including guidance on alternative serializers, see the [BinaryFormatter migration guide](../../../../standard/serialization/binaryformatter-migration-guide/index.md). |
| 37 | + |
| 38 | +## Affected APIs |
| 39 | + |
| 40 | +- <xref:System.Runtime.Serialization.Formatters.Binary.BinaryFormatter?displayProperty=fullName> |
| 41 | + |
| 42 | +## See also |
| 43 | + |
| 44 | +- [Announcement: BinaryFormatter is being removed in .NET 9](https://github.com/dotnet/runtime/issues/98245) |
| 45 | +- [BinaryFormatter disabled across most project types (.NET 8)](../8.0/binaryformatter-disabled.md) |
| 46 | +- [BinaryFormatter serialization APIs produce compiler errors (.NET 7)](../7.0/binaryformatter-apis-produce-errors.md) |
| 47 | +- [SerializationFormat.Binary is obsolete (.NET 7)](../7.0/serializationformat-binary.md) |
| 48 | +- [BinaryFormatter serialization methods are obsolete (.NET 5)](../5.0/binaryformatter-serialization-obsolete.md) |
0 commit comments