BinaryFormatter is disabled in WinForms or WPF projects in preview6
See original GitHub issueDescribe the bug
The intent behind this change - https://github.com/dotnet/sdk/commit/ccfcbe828cda905f1f995f63f26485dd9a7a7dd5 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.
Issue Analytics
- State:
- Created 4 months ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
Verified issue https://github.com/microsoft/winforms-designer/issues/5233 on .NET SDK 8.0.100-preview.5.23301.12 test pass build, it was fixed. In winforms VB project, ‘Explorer Form’ template form designer(contains ImageList) can be loaded successfully.
This appears to be a regression from 8.0 Preview 4, where the scenario worked correctly. I’m trying to narrow down the change.