dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.42k stars 984 forks source link

[dotnet-sdk-9.0.100-preview.6.24325.8] mRemote launch failed with an exception : PlatformNotSupportedException: BinaryFormatter serialization and deserialization have been removed." #11599

Closed Junjun-zhao closed 4 months ago

Junjun-zhao commented 4 months ago

.NET version

Dotnet Info:

.NET SDK:
 Version:           9.0.100-preview.6.24325.8
 Commit:            89054b0c37
 Workload version:  9.0.100-manifests.29b7987d
 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.6.24325.8\

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

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

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

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-preview.6.24324.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-preview.6.24321.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 9.0.0-preview.6.24322.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Did it work in .NET Framework?

Not tested/verified

Did it work in any of the earlier releases of .NET Core or .NET 5+?

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.6.24325.8: Fail 3). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.7.24321.3: Fail

Issue description

When run the 3rd party application with the latest .NET 9 build "dotnet-sdk-9.0.100-preview.6.24325.8", it failed to launch with error: "The type initializer for 'BrightIdeasSoftware.ObjectListView' threw an exception." After debugging the source code, we found this exception is caused by "PlatformNotSupportedException: BinaryFormatter serialization and deserialization have been removed.".

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

Steps to reproduce

  1. Change the runtime.config file to let the app run against with dotnet-sdk-9.0.100-preview.6.24325.8.
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "9.0.0-preview.6.24321.8"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "9.0.0-preview.6.24322.3"
      }
    ],
  2. Turn on EnableUnsafeBinaryFormatterSerialization switch in runtime.config file:
    "configProperties": {
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true
    }
  3. Launch mRemoteNG.exe.

Expected Result: Launch successfully.

Actual Result: Launch failed with error: image mRemotingNG_BugReproSteps

The type initializer for 'BrightIdeasSoftware.ObjectListView' threw an exception.
StackTrace:
at BrightIdeasSoftware.ObjectListView.get_IsVistaOrLater()
   at BrightIdeasSoftware.VirtualObjectListView.get_ShowGroups()
   at BrightIdeasSoftware.VirtualObjectListView.BuildList(Boolean shouldPreserveSelection)
   at BrightIdeasSoftware.VirtualObjectListView.set_VirtualListDataSource(IVirtualListDataSource value)
   at BrightIdeasSoftware.VirtualObjectListView..ctor()
   at BrightIdeasSoftware.TreeListView..ctor()
   at mRemoteNG.UI.Controls.ConnectionTree.ConnectionTree..ctor() in C:\Source\mRemoteNG\mRemoteNG\UI\Controls\ConnectionTree\ConnectionTree.cs:line 69
   at mRemoteNG.UI.Window.ConnectionTreeWindow.InitializeComponent() in C:\Source\mRemoteNG\mRemoteNG\UI\Window\ConnectionTreeWindow.Designer.cs:line 24
   at mRemoteNG.UI.Window.ConnectionTreeWindow..ctor(DockContent panel) in C:\Source\mRemoteNG\mRemoteNG\UI\Window\ConnectionTreeWindow.cs:line 45
   at mRemoteNG.UI.Window.ConnectionTreeWindow..ctor() in C:\Source\mRemoteNG\mRemoteNG\UI\Window\ConnectionTreeWindow.cs:line 36
   at mRemoteNG.App.Windows.get_TreeForm() in C:\Source\mRemoteNG\mRemoteNG\App\Windows.cs:line 23
   at mRemoteNG.UI.Forms.FrmMain.SetMenuDependencies() in C:\Source\mRemoteNG\mRemoteNG\UI\Forms\frmMain.cs:line 289
   at mRemoteNG.UI.Forms.FrmMain.FrmMain_Load(Object sender, EventArgs e) in C:\Source\mRemoteNG\mRemoteNG\UI\Forms\frmMain.cs:line 171
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Control.CreateControl(Boolean ignoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at mRemoteNG.UI.Forms.FrmMain.WndProc(Message& m) in C:\Source\mRemoteNG\mRemoteNG\UI\Forms\frmMain.cs:line 598
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

Inner Exception when debugging code:

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

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": {
      "mRemoteNG/1.77.3-dev": {
        "dependencies": {
          "System.Runtime.Serialization.Formatters": "9.0.0-preview.6.24327.7"
        },
    ......
      "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"
    }
    }
    ......


@dotnet-actwx-bot @dotnet/compat
elachlan commented 4 months ago

Related: #6267

elachlan commented 4 months ago

Application needs to add <EnableUnsafeBinaryFormatterSerialization>True</EnableUnsafeBinaryFormatterSerialization> and/or BrightIdeasSoftware.ObjectListView will need to be updated to use a different form of serialization or add a typeconverter.

Junjun-zhao commented 4 months ago

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