question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

BinaryFormatter is disabled in WinForms or WPF projects in preview6

See original GitHub issue

Describe 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

  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.

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Amy-Li03commented, Jun 5, 2023

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. Fixed

1reaction
GrabYourPitchforkscommented, May 31, 2023

This appears to be a regression from 8.0 Preview 4, where the scenario worked correctly. I’m trying to narrow down the change.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BinaryFormatter is disabled in WinForms or WPF projects ...
Have BinaryFormatter.Serialize/Deserialize methods enabled in .NET8. However in SDK Preview6, we are getting a NotSupportedException ...
Read more >
BinaryFormatter disabled across most project types - .NET
Starting in .NET 8, the affected methods throw a NotSupportedException at run time across all project types except Windows Forms and WPF. The ......
Read more >
BinaryFormatter not supported in .net 5 app when loading ...
As a workaround there is an option to re enable binaryformatter in .Net 5 asp.Net apps by adding the following to the project...
Read more >
BinaryFormatter Serialization and Deserialization Are Disabled
Learn why .NET 5 projects may throw the error 'BinaryFormatter serialization and deserialization are disabled within this application' and how to fix it....
Read more >
wpf vs winforms
Tanya-Solyanik changed the title BinaryFormatter is disabled in new WinForms or WPF projects in preview6 BinaryFormatter is disabled in WinForms or WPF ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found