The following is an adapted version of a test in Export-FormatData.Tests.ps1 that tests round-tripping of exporting all format data and importing it into a new session, to ensure that all data is preserved.
If you use -PowerShellVersion 5.1 to ensure that all format-data definitions are reported (the need for which will go away with #11270), round-tripping no longer works properly - certain types no longer have format data associated with them after importing.
This may be related to duplicate data existing among the built-in formats - see #11307 - and that perhaps duplicates that cover additional types are not getting imported.
Steps to reproduce
$tmpFile = [IO.Path]::GetTempFileName() + '.ps1xml'
$fd = Get-FormatData -PowerShellVersion 5.1
$fd | Export-FormatData -path $tmpFile -IncludeScriptBlock
$sessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
$sessionState.Formats.Clear()
$sessionState.Types.Clear()
$runspace = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace($sessionState)
$runspace.Open()
$runspace.CreatePipeline("Update-FormatData -AppendPath $tmpFile").Invoke()
$actualAllFormat = $runspace.CreatePipeline("Get-FormatData -PowerShellVersion 5.1").Invoke()
Remove-Item $tmpFile
$typesBefore = $fd | % TypeNames | Sort-Object -Unique
$typesAfter = $actualAllFormat | % TypeNames | Sort-Object -Unique
Compare-Object $typesBefore $typesAfter -PassThru | Should -Be $null
Expected behavior
The test should succeed.
Actual behavior
The test fails, because several types no longer have format data associated with them in the new session.
Expected $null, but got @(
'Deserialized.System.RuntimeType',
'Microsoft.Win32.RegistryKey',
'System.IO.FileInfo',
'System.Management.Automation.LineBreakpoint',
'System.Management.Automation.TreatAs.RegistryValue',
'System.Management.Automation.VariableBreakpoint', 'System.Security.Cryptography.X509Certificates.X509Store'
)
Environment data
PowerShell Core v7.0.0-preview.6
The following is an adapted version of a test in
Export-FormatData.Tests.ps1that tests round-tripping of exporting all format data and importing it into a new session, to ensure that all data is preserved.If you use
-PowerShellVersion 5.1to ensure that all format-data definitions are reported (the need for which will go away with #11270), round-tripping no longer works properly - certain types no longer have format data associated with them after importing.This may be related to duplicate data existing among the built-in formats - see #11307 - and that perhaps duplicates that cover additional types are not getting imported.
Steps to reproduce
Expected behavior
The test should succeed.
Actual behavior
The test fails, because several types no longer have format data associated with them in the new session.
Environment data