Prerequisites
Steps to reproduce
- Create a PSD1 with the following contents:
[ordered]@{
TestCase = "foo"
TestCase2 = "bar"
TestCase3 = [ordered]@{
"bar" = "baz"
"baz" = "bar"
}
}
- Save the file to disk, e.g. name
MRTC.psd1.
- Call
import-powershelldatafile .\path\to\MRTC.psd1 inside another order-sensitive function, like ConvertTo-Json.
Expected behavior
PS> convertto-json (Import-PowerShellDataFile .\MRTC.psd1 -SkipLimitCheck)
{
"TestCase": "foo",
"TestCase3": {
"baz": "bar",
"bar": "baz"
},
"TestCase2": "bar"
}
Actual behavior
PS> Import-PowerShellDataFile .\MRTC.psd1
Import-PowerShellDataFile: Cannot generate a PowerShell object for a ScriptBlock evaluating dynamic expressions. Dynamic expression: @{
TestCase = "foo"
TestCase2 = "bar"
TestCase3 = [ordered]@{
"bar" = "baz"
"baz" = "bar"
}
}.
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: @{
TestCase = "foo"
TestCase2 = "bar"
TestCase3 = [ordered]@{
"bar" = "baz"
"baz" = "bar"
}
}.
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 : 26
Line : Import-PowerShellDataFile .\MRTC.psd1
Statement : Import-PowerShellDataFile .\MRTC.psd1
PositionMessage : At line:1 char:1
+ Import-PowerShellDataFile .\MRTC.psd1
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : Import-PowerShellDataFile
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
Environment data
Name Value
---- -----
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Visuals
No response
Prerequisites
Steps to reproduce
MRTC.psd1.import-powershelldatafile .\path\to\MRTC.psd1inside another order-sensitive function, likeConvertTo-Json.Expected behavior
Actual behavior
Error details
Environment data
Visuals
No response