dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.28k stars 5.91k forks source link

[Breaking change]: BinaryFormatter disabled across almost all project types by default #34891

Closed GrabYourPitchforks closed 1 year ago

GrabYourPitchforks commented 1 year ago

Description

Beginning with .NET 8 Preview 4, the BinaryFormatter.Serialize and BinaryFormatter.Deserialize methods will throw NotSupportedException across nearly all project types, including console applications.

A compatibility switch exists for applications which need to reenable BinaryFormatter behavior. See below for details.

Version

.NET 8 Preview 4

Previous behavior

In .NET 7, the BinaryFormatter.Serialize and BinaryFormatter.Deserialize methods were marked obsolete as error. However, if an application suppressed the obsoletion, the methods could still be called and would still function properly in most project types (excluding aspnet, wasm, and MAUI). For example, the APIs would function properly within a console app.

New behavior

In .NET 8 Preview 4, these methods will throw NotSupportedException at runtime across all project types except WinForms and WPF. The APIs continue to remain obsolete-as-error across all project types, including WinForms and WPF.

Type of breaking change

Reason for change

This is the next stage of the BinaryFormatter obsoletion plan, preparing for BinaryFormatter's eventual removal from .NET. See earlier breaking change notifications for additional context:

Recommended action

The best course of action is to migrate away from BinaryFormatter due to its security and reliability flaws.

However, should you need to continue using BinaryFormatter, please review the Recommended action section of the .NET 7 breaking change notification. That document provides a compatibility switch that can be set in your application's project file to reenable BinaryFormatter functionality. That compatibility switch continues to be honored in .NET 8.

Feature area

Serialization

Affected APIs


Associated WorkItem - 91247

IS4Code commented 1 year ago

Not only is .NET Core still missing things present in .NET Framework, but now others are being removed. Lol.