Skip to content

Disable BinaryFormatter across most .NET 8 project types #31591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 6, 2023

Conversation

GrabYourPitchforks
Copy link
Member

@GrabYourPitchforks GrabYourPitchforks commented Apr 4, 2023

Ref: https://github.com/dotnet/designs/blob/main/accepted/2020/better-obsoletion/binaryformatter-obsoletion.md

In .NET 7, we obsoleted (as error) the BinaryFormatter APIs, but existing compiled code could still call it and it would work. There was no runtime block except in certain project types like aspnet, Blazor, and MAUI.

In .NET 8, we're flipping this so that BinaryFormatter is now disabled across all project types except WinForms and WPF, which need a little bit more time to work on removal. If you retarget a .NET 7 console application to .NET 8 and that app was using BinaryFormatter under the covers, calls to BF will now fail at runtime.

Just like in .NET 7, applications can continue to use the <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization> compat switch to opt back in to restoring BinaryFormatter behavior. Setting that compat switch suppresses both the compile-time error (same as .NET 7) and the .NET 8 runtime disablement.

For more information on the matrix, see the comment in Microsoft.NET.Sdk.targets within this PR.

@ghost ghost added Area-Infrastructure untriaged Request triage from a team member labels Apr 4, 2023
@baronfel
Copy link
Member

baronfel commented Apr 4, 2023

Paging @vzarytovskii for a matching change in the FSharp SDK targets, which are stored in dotnet/fsharp.

…targets

Co-authored-by: Jeremy Kuhne <jeremy.kuhne@microsoft.com>
@jeffhandley jeffhandley changed the title Killbit BinaryFormatter across most .NET 8 project types Disable BinaryFormatter across most .NET 8 project types Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Infrastructure untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants