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] JexusManager get System.PlatformNotSupportedException: BinaryFormatter serialization and deserialization have been removed. #11598

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.24317.13: 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: System.PlatformNotSupportedException: BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.

Application Name: JexusManager (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/2110659 Github Link: https://github.com/jexuswebserver/JexusManager

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 and Enable BinaryFormatter.

"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"
      }
    ],
"configProperties": {
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": true
    }
  1. Launching JexusManager.exe.
  2. Click “Yes” button if it exists.
  3. Click “OK” menu if it exists.
  4. Expand “IIS Express” item.
  5. Double click “Global” item.
  6. Double click “URL Rewrite” item.
  7. Click “Add Rule” button.
  8. Click Blank rule item.
  9. Click the Ok button.

Expected Result: Successfully jump to the interface.

Actual Result: Pop up error window.

Exception details (Exception comes from error window):

System.InvalidOperationException: menu item Add Rule(s)... function Add
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.PlatformNotSupportedException: BinaryFormatter serialization and deserialization have been removed. See https://aka.ms/binaryformatter for more information.
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
   at System.Resources.ResourceReader.<>c__DisplayClass7_0`1.<CreateUntypedDelegate>b__0(Object obj, Stream stream)
   at System.Resources.ResourceReader.DeserializeObject(Int32 typeIndex)
   at System.Resources.ResourceReader._LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)
   at System.Resources.ResourceReader.LoadObjectV2(Int32 pos, ResourceTypeCode& typeCode)
   at System.Resources.ResourceReader.LoadObject(Int32 pos, ResourceTypeCode& typeCode)
   at System.Resources.RuntimeResourceSet.ReadValue(ResourceReader reader, Int32 dataPos, Boolean isString, ResourceLocator& locator)
   at System.Resources.RuntimeResourceSet.GetObject(String key, Boolean ignoreCase, Boolean isString)
   at System.Resources.ResourceManager.GetObject(String name, CultureInfo culture, Boolean wrapUnmanagedMemStream)
   at MakarovDev.ExpandCollapsePanel.Properties.Resources.get__1downarrow1()
   at MakarovDev.ExpandCollapsePanel.ExpandCollapseButton.InitializeComponent()
   at MakarovDev.ExpandCollapsePanel.ExpandCollapseButton..ctor()
   at MakarovDev.ExpandCollapsePanel.ExpandCollapsePanel.InitializeComponent()
   at MakarovDev.ExpandCollapsePanel.ExpandCollapsePanel..ctor()
   at JexusManager.Features.Rewrite.Inbound.InboundRulePage.InitializeComponent() in C:\Source\JexusManager\JexusManager.Features.Rewrite\Inbound\InboundRulePage.Designer.cs:line 42
   at JexusManager.Features.Rewrite.Inbound.InboundRulePage..ctor() in C:\Source\JexusManager\JexusManager.Features.Rewrite\Inbound\InboundRulePage.cs:line 90
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   --- End of inner exception stack trace ---
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
   at Microsoft.Web.Management.Client.NavigationItem.get_Page() in C:\Source\JexusManager\Microsoft.Web.Management\Client\NavigationItem.cs:line 35
   at JexusManager.Services.NavigationService.NavigateToItem(NavigationItem item, Boolean initializing) in C:\Source\JexusManager\JexusManager\Services\NavigationService.cs:line 65
   at JexusManager.Services.NavigationService.Navigate(Connection connection, ManagementConfigurationPath configurationPath, Type pageType, Object navigationData) in C:\Source\JexusManager\JexusManager\Services\NavigationService.cs:line 30
   at JexusManager.Features.Rewrite.RewriteFeature.Add() in C:\Source\JexusManager\JexusManager.Features.Rewrite\RewriteFeature.cs:line 305
   at JexusManager.Features.Rewrite.RewriteFeature.FeatureTaskList.Add() in C:\Source\JexusManager\JexusManager.Features.Rewrite\RewriteFeature.cs:line 123
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
   --- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Microsoft.Web.Management.Client.TaskList.InvokeMethod(String methodName, Object userData) in C:\Source\JexusManager\Microsoft.Web.Management\Client\TaskList.cs:line 23
   at JexusManager.Features.TaskItemExtensions.<>c__DisplayClass3_0.<TaskItemFill>b__0(Object o, EventArgs args) in C:\Source\JexusManager\JexusManager.Shared\Features\TaskItemExtensions.cs:line 90
   --- End of inner exception stack trace ---
   at JexusManager.Features.TaskItemExtensions.<>c__DisplayClass3_0.<TaskItemFill>b__0(Object o, EventArgs args) in C:\Source\JexusManager\JexusManager.Shared\Features\TaskItemExtensions.cs:line 101
   at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)

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=v7.0": {
      "JexusManager/13.0.23": {
        "dependencies": {
          "System.Runtime.Serialization.Formatters": "9.0.0-preview.6.24327.7"
        },
        "runtime": {
          "JexusManager.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"
    }
    }
    }
    ......

    @dotnet-actwx-bot @dotnet/compat

elachlan commented 4 months ago

Related: #6267

elachlan commented 4 months ago

Application needs to add <EnableUnsafeBinaryFormatterSerialization>True</EnableUnsafeBinaryFormatterSerialization>.

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.