dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.55k stars 4.54k forks source link

[dotnet-sdk-9.0.100-preview.7.24321.3] NetTopologySuite launch failed with error: System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed #103952

Open Junjun-zhao opened 1 week ago

Junjun-zhao commented 1 week ago

Description

When run the 3rd party application with the latest .NET 9 build "dotnet-sdk-9.0.100-preview.7.24321.3", it failed to launch with error: System.PlatformNotSupportedException: 'BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.'

Reproduction Steps

Minimal Repro steps (Demo attached):

  1. Create a default 8.0 console project.
  2. Add the following code to Program.cs.
    using System.Runtime.Serialization.Formatters.Binary;
    BinaryFormatter formatter = new BinaryFormatter();
    formatter.Serialize(new FileStream("test", FileMode.Create), "test");
  3. Add the following code to .csproj file.
    <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
  4. Build the project.
  5. Change the runtime.config file to let the app run against with dotnet-sdk-9.0.100-preview.7.24321.3.
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "9.0.0-preview.6.24321.8"
      }
    ],
    "configProperties": {
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true
    }
  6. Launch the project.

Expected behavior

Launch successfully.

Actual behavior

Launch failed with error:

System.PlatformNotSupportedException: 'BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.'

App Repro steps: 1.Set EnableUnsafeBinaryFormatterSerialization switch to True and set 9.0.100-preview.6.24325.8 runtime version in NetTopologySuiteTest02\NetTopologySuite.Tests.NUnit.runtimeconfig.json

"frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "9.0.0-preview.6.24321.8"
      }
    ],
"configProperties": {
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true
    }
  1. Cd to NetTopologySuite\NetTopologySuiteTest02
  2. Run "dotnet vstest NetTopologySuite.Tests.NUnit.dll"

Expected Result: All pass.

Actual Result: Error Message:

   System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.
  Stack Trace:
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at NetTopologySuite.Tests.NUnit.Utilities.SerializationUtility.Serialize[T](T obj) in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Utilities\SerializationUtility.cs:line 15
   at NetTopologySuite.Tests.NUnit.Geometries.Implementation.CoordinateSequenceTestBase.TestSerializable() in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Geometries\Implementation\CoordinateSequenceTestBase.cs:line 87
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
  Failed TestSerializable [< 1 ms]
  Error Message:
   System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.
  Stack Trace:
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at NetTopologySuite.Tests.NUnit.Utilities.SerializationUtility.Serialize[T](T obj) in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Utilities\SerializationUtility.cs:line 15
   at NetTopologySuite.Tests.NUnit.Geometries.Implementation.CoordinateSequenceTestBase.TestSerializable() in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Geometries\Implementation\CoordinateSequenceTestBase.cs:line 87
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
  Failed TestSerializable [< 1 ms]
  Error Message:
   System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.
  Stack Trace:
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at NetTopologySuite.Tests.NUnit.Utilities.SerializationUtility.Serialize[T](T obj) in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Utilities\SerializationUtility.cs:line 15
   at NetTopologySuite.Tests.NUnit.Geometries.Implementation.CoordinateSequenceTestBase.TestSerializable() in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Geometries\Implementation\CoordinateSequenceTestBase.cs:line 87
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
  Failed TestSerializable [< 1 ms]
  Error Message:
   System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.
  Stack Trace:
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at NetTopologySuite.Tests.NUnit.Utilities.SerializationUtility.Serialize[T](T obj) in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Utilities\SerializationUtility.cs:line 15
   at NetTopologySuite.Tests.NUnit.Geometries.Implementation.CoordinateSequenceTestBase.TestSerializable() in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Geometries\Implementation\CoordinateSequenceTestBase.cs:line 87
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
  Failed TestSerializable [< 1 ms]
  Error Message:
   System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.
  Stack Trace:
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at NetTopologySuite.Tests.NUnit.Utilities.SerializationUtility.Serialize[T](T obj) in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Utilities\SerializationUtility.cs:line 15
   at NetTopologySuite.Tests.NUnit.Geometries.Implementation.CoordinateSequenceTestBase.TestSerializable() in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Geometries\Implementation\CoordinateSequenceTestBase.cs:line 87
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
  Failed TestSerializable [< 1 ms]
  Error Message:
   System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.
  Stack Trace:
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at NetTopologySuite.Tests.NUnit.Utilities.SerializationUtility.Serialize[T](T obj) in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Utilities\SerializationUtility.cs:line 15
   at NetTopologySuite.Tests.NUnit.Geometries.Implementation.CoordinateSequenceTestBase.TestSerializable() in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Geometries\Implementation\CoordinateSequenceTestBase.cs:line 87
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
  Failed TestSerializable [< 1 ms]
  Error Message:
   System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.
  Stack Trace:
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at NetTopologySuite.Tests.NUnit.Utilities.SerializationUtility.Serialize[T](T obj) in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Utilities\SerializationUtility.cs:line 15
   at NetTopologySuite.Tests.NUnit.Geometries.Implementation.CoordinateSequenceTestBase.TestSerializable() in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Geometries\Implementation\CoordinateSequenceTestBase.cs:line 87
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
  Failed TestSerializable [< 1 ms]
  Error Message:
   System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.
  Stack Trace:
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at NetTopologySuite.Tests.NUnit.Utilities.SerializationUtility.Serialize[T](T obj) in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Utilities\SerializationUtility.cs:line 15
   at NetTopologySuite.Tests.NUnit.Geometries.Implementation.CoordinateSequenceTestBase.TestSerializable() in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Geometries\Implementation\CoordinateSequenceTestBase.cs:line 87
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
  Failed TestSerialization [427 ms]
  Error Message:
   System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.
  Stack Trace:
     at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at NetTopologySuite.Tests.NUnit.Utilities.SerializationUtility.Serialize[T](T obj) in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Utilities\SerializationUtility.cs:line 15
   at NetTopologySuite.Tests.NUnit.Index.Quadtree.QuadtreeTest.TestSerialization() in C:\source\NetTopologySuite\test\NetTopologySuite.Tests.NUnit\Index\Quadtree\QuadtreeTest.cs:line 43
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Regression?

Yes Verify Scenarios: 1). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.6.24314.10: Pass 2). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.7.24321.3: Fail

Known Workarounds

No. Tried the following steps:

  1. Turn on the AppContext Switch like <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
  2. Install the System.Runtime.Serialization.Formatters nuget package (Failed. Because it is not compatible with this .NET 6.0 App. The supported .NET version of System.Runtime.Serialization.Formatters nuget package is .NET 8)

Configuration

Application Name: NetTopologySuite(UnitTest) OS: Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-9.0.100-preview.7.24321.3 App & Source Location checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2110672 Github Link: https://github.com/mRemoteNG/mRemoteNG

Dotnet Info:

.NET SDK:
 Version:           9.0.100-preview.7.24321.3
 Commit:            941ec62ab2
 Workload version:  9.0.100-manifests.cc027b4d
 MSBuild version:   17.11.0-preview-24318-05+4a45d5633

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-preview.7.24321.3\

Host:
  Version:      9.0.0-preview.6.24319.11
  Architecture: x64
  Commit:       static

.NET SDKs installed:
  9.0.100-preview.7.24321.3 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-preview.6.24320.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-preview.6.24319.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 9.0.0-preview.7.24320.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other information

Question:

  1. BinaryFormatter was removed in current .NET 9.0.100-preview.7.24321.3, Could you please confirm is this expected behavior according to the schedule?
  2. According to Announcement: BinaryFormatter is being removed in .NET 9 · Issue #98245 · dotnet/runtime (github.com) , a new NuGet package will be provided. Will team be going to create a breaking change with recommended Action and NuGet Package Information Provided for .NET 9 Preview 7?

@dotnet-actwx-bot @dotnet/compat

julealgon commented 1 week ago

Expected behavior Launch successfully.

I don't understand why you think that was the expected behavior given all the annoucements made regarding BinaryFormatter. This is obviously by design.

dotnet-policy-service[bot] commented 1 week ago

Tagging subscribers to this area: @dotnet/area-system-runtime See info in area-owners.md if you want to be subscribed.

jkotas commented 1 week ago

cc @adamsitnik @bartonjs

bartonjs commented 1 week ago

This is by design.

1) Everyone should stop using BinaryFormatter. 2) To the extent that (1) is not possible, the application can reference the System.Runtime.Serialization.Formatters nuget package (the 9.0 version line), and that will bring BinaryFormatter back to the functionality it had in .NET 8.

PriyaPurkayastha commented 1 week ago

The apps mentioned in this bug are real world apps sourced from GitHub and we are aware of BinaryFormatter removal. We will help redirect issue to app repos after investigation is completed by Winforms/WPF teams. cc @JeremyKuhne since he is taking a look at the failures. This bug is logged by the .NET AppCompat validation team that is confirming behavior for runtime compat scenarios and ensuring that workarounds/guidance planned for customers running into similar issues are available and work. We are also helping to get confirmation that the failures that we are seeing are expected (all potential code paths or BinaryFormatter usages identified by the representative set of apps in our lab, are fully understood).