-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
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
- Install the latest SDK
- Create a winforms application targeting .NET 8 in the VS (app is here https://github.com/Tanya-Solyanik/Repro)
- Add
<NoWarn>SYSLIB0011</NoWarn>to the project file - Add a call to BinaryFormatter.Serialize()
- 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.