Skip to content

Commit 8f809fc

Browse files
committed
Replace BinaryFormatter with PSSerializer
Since the former has been removed from PowerShell 7.4 (because it was removed from .NET 7) and the latter can accomplish the same thing. The default depth is 1, so we need to specify. Best I could find was that the prior implementation defaulted to a depth of 64, so we're going with that.
1 parent 4df5f3e commit 8f809fc

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

Helpers.ps1

+2-8
Original file line numberDiff line numberDiff line change
@@ -394,14 +394,8 @@ function DeepCopy-Object
394394
[PSCustomObject] $InputObject
395395
)
396396

397-
$memoryStream = New-Object System.IO.MemoryStream
398-
$binaryFormatter = New-Object System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
399-
$binaryFormatter.Serialize($memoryStream, $InputObject)
400-
$memoryStream.Position = 0
401-
$DeepCopiedObject = $binaryFormatter.Deserialize($memoryStream)
402-
$memoryStream.Close()
403-
404-
return $DeepCopiedObject
397+
$serialData = [System.Management.Automation.PSSerializer]::Serialize($InputObject, 64)
398+
return [System.Management.Automation.PSSerializer]::Deserialize($serialData)
405399
}
406400

407401
function New-TemporaryDirectory

0 commit comments

Comments
 (0)