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

[Bug]: BinaryFormatter.Serialize in Copy-psObject causes exception to be thrown when running under .NET 8 #79

Closed
dom34 opened this issue Nov 24, 2023 · 2 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@dom34
Copy link

dom34 commented Nov 24, 2023

What happened?

When I run Monkey365 using .NET 8, several exceptions are raised. The error message is:

[Copy-psObject] - System.Management.Automation.MethodInvocationException: Exception calling "Serialize" with "2" argument(s): "BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information."

This is a breaking change in .NET 8

https://learn.microsoft.com/en-us/dotnet/core/compatibility/serialization/8.0/binaryformatter-disabled

Previous behavior
In .NET 7, the BinaryFormatter.Serialize(Stream, Object) and BinaryFormatter.Deserialize(Stream) methods were marked obsolete and raised an error at compile time. However, if your application suppressed the obsoletion, it could still call the methods and they functioned properly in most project types (excluding ASP.NET, WASM, and MAUI). For example, the APIs functioned correctly in a console app.

New behavior
Starting in .NET 8, the affected methods throw a NotSupportedException at run time across all project types except Windows Forms and WPF. The APIs continue to remain obsolete (as error) across all project types, including Windows Forms and WPF.

How to reproduce it

Make sure your instance of Powershell is using the .NET 8 runtime:

user@debian12$ pwsh
PowerShell 7.4.0
PS /home/user> [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription
.NET 8.0.0

then import and invoke the module in the usual way. The exceptions will be logged.

Expected behavior

No exceptions

Screenshots or Logs

[14:52:21:537] - [Copy-psObject] - System.Management.Automation.MethodInvocationException: Exception calling "Serialize" with "2" argument(s): "BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information."
 ---> System.NotSupportedException: BinaryFormatter serialization and deserialization are disabled within this application. See https://aka.ms/binaryformatter for more information.
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph)
   at CallSite.Target(Closure, CallSite, Object, Object, Object)
   --- End of inner exception stack trace ---
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame). LineNumber:  - exception - debian12 -

From where are you running Monkey365?

Please, complete the following information:

  • Resource: Workstation
  • OS: Debian 12 Linux
  • PowerShell Version:
PS /home/user> $PsVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Debian GNU/Linux 12 (bookworm)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
  • Monkey365 Version: Monkey365 v0.91.1-beta

Additional context
I am using the PowerShell snap for Linux - the full package has not been fully tested on Debian 12

@dom34 dom34 added bug Something isn't working status/needs-triage Needs triage labels Nov 24, 2023
@dom34 dom34 changed the title [Bug]: .NET version 8 causes BinaryFormatter.Serialize etc. to [Bug]: BinaryFormatter,Serialize in Copy-psObject causes exception to be thrown when running under .NET 8 Nov 24, 2023
@dom34 dom34 changed the title [Bug]: BinaryFormatter,Serialize in Copy-psObject causes exception to be thrown when running under .NET 8 [Bug]: BinaryFormatter.Serialize in Copy-psObject causes exception to be thrown when running under .NET 8 Nov 24, 2023
@silverhack
Copy link
Owner

Hi @dom34,

Good catch! And thanks for submitting this issue, I'll fix it shortly.

@silverhack silverhack added good first issue Good for newcomers and removed status/needs-triage Needs triage labels Nov 24, 2023
@silverhack silverhack self-assigned this Nov 24, 2023
@silverhack
Copy link
Owner

Fixed in main branch.

Cheers,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants