dotnet / dotnet/announcements

BinaryFormatter removal from .NET 9 is complete

Open
#317 0 comments 0 reactions 0 assignees View on GitHub
.NET 9.0 Breaking Change Security
Dominant language
No language data
Stars
1.4k
Forks
53
PR merge metrics
No merged PRs in 30d

Description

> This issue is a locked mirror of https://github.com/dotnet/runtime/issues/106240. See that issue for discussion.

As [announced earlier](https://github.com/dotnet/announcements/issues/293), starting with .NET 9, we no longer include an implementation of `BinaryFormatter` in the runtime (.NET Framework remains unchanged). The APIs are still present, but their implementation always throws an exception, regardless of project type. Hence, setting the existing backwards compatibility flag is no longer sufficient to use `BinaryFormatter`.

* We published the [BinaryFormatter migration guide][migration-guide]. We'd appreciate if could give it a read and give us feedback by filling issues in the [dotnet/docs] repo.
* If you experience issues related to BinaryFormatter's removal not addressed in this migration guide, please file an issue in the [dotnet/runtime][dotnet/runtime] repo and indicate that the issue is related to the removal of `BinaryFormatter`.

### Why was it removed?

*[Docs][security-guide]*

The primary reason is that BinaryFormatter is unsafe. Any deserializer, binary or text, that allows its input to carry information about the objects to be created is a security problem waiting to happen. There is a common weakness enumeration (CWE) that describes the issue: [CWE-502 "Deserialization of Untrusted Data"][CWE502]. `BinaryFormatter` is such a deserializer. We also cover this in the [BinaryFormatter security guide][security-guide].

### What are my options to move forward?

*[Docs][migration-guide]*

You have two options to address the removal of `BinaryFormatter`'s implementation:

1. **Migrate away from BinaryFormatter**. We strongly recommend you to investigate options to stop using `BinaryFormatter` due to the associated security risks. The [BinaryFormatter migration guide][migration-guide] lists several options.

2. **Keep using BinaryFormatter**. If you need to continue using `BinaryFormatter` in .NET 9, you need to depend on the unsupported [System.Runtime.Serialization.Formatters][compat-pack] NuGet package, which restores the unsafe legacy functionality and replaces the throwing implementation.

[compat-pack]: https://learn.microsoft.com/dotnet/standard/serialization/binaryformatter-migration-guide/compatibility-package
[migration-guide]: https://learn.microsoft.com/dotnet/standard/serialization/binaryformatter-migration-guide/
[security-guide]: https://learn.microsoft.com/dotnet/standard/serialization/binaryformatter-security-guide
[CWE502]: https://cwe.mitre.org/data/definitions/502.html
[dotnet/docs]: https://github.com/dotnet/docs/issues/new?assignees=&labels=&projects=&template=01-general-issue.yml
[dotnet/runtime]: https://github.com/dotnet/runtime/issues/new

> This issue is a locked mirror of https://github.com/dotnet/runtime/issues/106240. See that issue for discussion.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.