Skip to content

Commit 983f01d

Browse files
authored
BinaryFormatter removal (#42054)
1 parent 3dba29c commit 983f01d

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

docs/core/compatibility/9.0.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ If you're migrating an app to .NET 9, the breaking changes listed here might aff
6565
| [Terminal logger is default](sdk/9.0/terminal-logger.md) | Behavioral change | Preview 1 |
6666
| [Warning emitted for .NET Standard 1.x](sdk/9.0/netstandard-warning.md) | Source incompatible | Preview 6 |
6767

68+
## Serialization
69+
70+
| Title | Type of change | Introduced version |
71+
|-----------------------------------------------------------------------------|-------------------|--------------------|
72+
| [BinaryFormatter always throws](serialization/9.0/binaryformatter-removal.md) | Behavioral change | Preview 6 |
73+
6874
## Windows Forms
6975

7076
| Title | Type of change | Introduced version |
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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)

docs/core/compatibility/toc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ items:
6060
href: sdk/9.0/terminal-logger.md
6161
- name: Warning emitted for .NET Standard 1.x targets
6262
href: sdk/9.0/netstandard-warning.md
63+
- name: Serialization
64+
items:
65+
- name: BinaryFormatter always throws
66+
href: serialization/9.0/binaryformatter-removal.md
6367
- name: Windows Forms
6468
items:
6569
- name: BindingSource.SortDescriptions doesn't return null
@@ -1802,6 +1806,10 @@ items:
18021806
href: core-libraries/5.0/utf-7-code-paths-obsolete.md
18031807
- name: Serialization
18041808
items:
1809+
- name: .NET 9
1810+
items:
1811+
- name: BinaryFormatter always throws
1812+
href: serialization/9.0/binaryformatter-removal.md
18051813
- name: .NET 8
18061814
items:
18071815
- name: BinaryFormatter disabled for most projects

0 commit comments

Comments
 (0)