Skip to content

BinaryFormatter is disabled in WinForms or WPF projects in preview6 #32941

@Tanya-Solyanik

Description

@Tanya-Solyanik

Describe the bug

The intent behind this change - ccfcbe8 was that projects with these properties

    <UseWindowsForms>true</UseWindowsForms>
    <UseWPF>true</UseWPF>

Have BinaryFormatter.Serialize/Deserialize methods enabled in .NET8. However in SDK Preview6, we are getting a NotSupportedException

To Reproduce

  1. Install the latest SDK
  2. Create a winforms application targeting .NET 8 in the VS (app is here https://github.com/Tanya-Solyanik/Repro)
  3. Add <NoWarn>SYSLIB0011</NoWarn> to the project file
  4. Add a call to BinaryFormatter.Serialize()
  5. Run that code

Result: System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.
at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
at WinFormsApp29.Form1.button1_Click(Object sender, EventArgs e) in C:\Users\tanyaso\source\repos\WinFormsApp29\WinFormsApp29\Form1.cs:line 17

Further technical details

  • Repros both in the VS and on the command line, as long as SDK preview 6.23280 is installed
  • If I add a switch
            AppContext.SetSwitch(
                "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization",
                isEnabled: true);

or
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
BinaryFormatter serializes successfully.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions