Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Junjun-zhao opened this issue Jun 25, 2024 · 6 comments
Assignees
Labels
area-System.Runtime binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it
Milestone

Comments

@Junjun-zhao
Copy link
Member

Junjun-zhao commented Jun 25, 2024

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");
  1. Add the following code to .csproj file.
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
  1. Build the project.
  2. 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
    }
  1. 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

Yes.

Try with the following steps:

  1. Turn on the AppContext Switch like <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
  2. Download and Extract System.Runtime.Serialization.Formatters nuget package.
  3. Copy System.Runtime.Serialization.Formatters.dll from nuget package folder to application publish folder.
  4. Update .deps.json file to registry System.Runtime.Serialization.Formatters.dll for application dependencies by adding following content in deps.json file:
"targets": {
    ".NETCoreApp,Version=v6.0": {
      "NetTopologySuite.Tests.NUnit/1.0.0": {
        "dependencies": {
         ......
          "System.Runtime.Serialization.Formatters": "9.0.0-preview.6.24327.7"
        },
        "runtime": {
          "NetTopologySuite.Tests.NUnit.dll": {}
        }
      },
      "System.Runtime.Serialization.Formatters/9.0.0-preview.6.24327.7": {
        "runtime": {
          "lib/net8.0/System.Runtime.Serialization.Formatters.dll": {
            "assemblyVersion": "9.0.0.0",
            "fileVersion": "9.0.24.32707"
          }
        }
      },
  "libraries": {
    "System.Runtime.Serialization.Formatters/9.0.0-preview.6.24327.7": {
      "type": "package",
      "serviceable": true,
      "sha512": "sha512-5S1E7KF/RzcZoRQ27BW3f6HX6zihRVz2utacaUWw4ilos2L4435PPn4rn8c+6Ltp4isTukBnw9K+FZCQHwCVPA==",
      "path": "system.runtime.serialization.formatters/9.0.0-preview.6.24327.7",
      "hashPath": "system.runtime.serialization.formatters.9.0.0-preview.6.24327.7.nupkg.sha512"
    },
......

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/NetTopologySuite/NetTopologySuite

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

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jun 25, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jun 25, 2024
@julealgon
Copy link

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.

@vcsjones vcsjones added area-Serialization binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jun 25, 2024
Copy link
Contributor

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

@jkotas
Copy link
Member

jkotas commented Jun 25, 2024

cc @adamsitnik @bartonjs

@bartonjs
Copy link
Member

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
Copy link

PriyaPurkayastha commented Jun 25, 2024

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

@Junjun-zhao Junjun-zhao changed the title [dotnet-sdk-9.0.100-preview.7.24321.3] Apps launch failed with error: System.PlatformNotSupportedException: 'BinaryFormatter serialization and deserialization have been removed [dotnet-sdk-9.0.100-preview.7.24321.3] NetTopologySuite launch failed with error: System.PlatformNotSupportedException : BinaryFormatter serialization and deserialization have been removed Jun 27, 2024
@stephentoub stephentoub removed the untriaged New issue has not been triaged by the area owner label Jul 2, 2024
@stephentoub stephentoub modified the milestones: Future, 9.0.0 Jul 2, 2024
@Junjun-zhao
Copy link
Member Author

Junjun-zhao commented Jul 15, 2024

Update for the workaround: It works well with the public Nuget package for the application. Closing this issue. We will file a new issue to notify the app owner about this change.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Runtime binaryformatter-migration Issues related to the removal of BinaryFormatter and migrations away from it
Projects
None yet
Development

No branches or pull requests

7 participants