Proj0032: Migrate away from BinaryFormatter

Starting with .NET 9, Microsoft no longer includes an implementation of BinaryFormatter in the runtime (it has been deprecated with the release of .NET 5). The APIs are still present, but their implementation always throws an exception, regardless of project type.

Setting the existing backwards compatibility flag is no longer sufficient to use BinaryFormatter with .NET 9, as is explained in this blog post.

Due to the fact that Microsoft discourages the usage as strongly as they can, this rule reports violations for all target frameworks, and also when used in combination with System.Runtime.Serialization.Formatters.

Non-compliant

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
    <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
  </PropertyGroup>
  
</Project>

Compliant

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net9.0</TargetFramework>
  </PropertyGroup>
  
</Project>