Skip to content

Exporting all format-data definitions and importing them into a pristine session results in missing definitions #11308

@mklement0

Description

@mklement0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions