Skip to content

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

Closed

Description

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

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Dec 10, 2019
  2. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  3. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  4. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  5. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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