Prerequisites
Context
Likely related to #27306. In #25090, there was some previously-discussed workarounds for lack of an in-box/intended functionality for order-preserving PSD1 import (like what ConvertFrom-Json and others do currently). [ordered] accelerators, with -SkipLimitCheck, worked "enough" for that need.
#19070 from long-ago highlighted the lack of ordered deserialization on Import-PowerShellDataFile, but that bug was closed due to no activity.
Now, that loophole is closed, meaning:
- Existing
[ordered]-tagged PSD1s no longer import.
- There's no way to deserialze PSD1s in an order-preserving manner, which is important for any round-trip encoding or workflows that depend on deterministic enumeration (e.g. CI)
Steps to reproduce
Import a PSD1 like the following:
[ordered]@{
A = [ordered]@{
B = 1
C = "2"
}
}
Expected behavior
PS> Import-PowerShellDataFile mrtc.psd1 -SkipLimitCheck
A
-----------
@{B=1, C=2}
Actual behavior
PS> Import-PowerShellDataFile mrtc.psd1 -SkipLimitCheck
Import-PowerShellDataFile: Cannot generate a PowerShell object for a ScriptBlock evaluating dynamic expressions. Dynamic expression: @{
A = [ordered]@{
B = 1
C = "2"
}
}
Error details
Exception :
Type : System.InvalidOperationException
TargetSite :
Name : SafeGetValue
DeclaringType : [System.Management.Automation.Language.Ast]
MemberType : Method
Module : System.Management.Automation.dll
Message : Cannot generate a PowerShell object for a ScriptBlock evaluating dynamic expressions. Dynamic expression: @{
A = [ordered]@{
B = 1
C = "2"
}
}.
Source : System.Management.Automation
HResult : -2146233079
StackTrace :
at System.Management.Automation.Language.Ast.SafeGetValue(Boolean skipHashtableSizeCheck)
at Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand.ProcessRecord()
at System.Management.Automation.CommandProcessor.ProcessRecord()
CategoryInfo : NotSpecified: (:) [Import-PowerShellDataFile], InvalidOperationException
FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.ImportPowerShellDataFileCommand
InvocationInfo :
MyCommand : Import-PowerShellDataFile
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 9
Line : Import-PowerShellDataFile mrtc.psd1 -SkipLimitCheck
Statement : Import-PowerShellDataFile mrtc.psd1 -SkipLimitCheck
PositionMessage : At line:1 char:1
+ Import-PowerShellDataFile mrtc.psd1 -SkipLimitCheck
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : import-PowerShellDataFile
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
Environment data
Name Value
---- -----
PSVersion 7.6.0
PSEdition Core
GitCommitId 7.6.0
OS Microsoft Windows 10.0.22631
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.4
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Prerequisites
Context
Likely related to #27306. In #25090, there was some previously-discussed workarounds for lack of an in-box/intended functionality for order-preserving PSD1 import (like what
ConvertFrom-Jsonand others do currently).[ordered]accelerators, with-SkipLimitCheck, worked "enough" for that need.#19070 from long-ago highlighted the lack of ordered deserialization on
Import-PowerShellDataFile, but that bug was closed due to no activity.Now, that loophole is closed, meaning:
[ordered]-tagged PSD1s no longer import.Steps to reproduce
Import a PSD1 like the following:
Expected behavior
Actual behavior
Error details
Environment data
Visuals
No response