Skip to content

Invoking commands via CommandInfo objects fails in pwsh 7 #12888

@vexx32

Description

@vexx32

Steps to reproduce

pwsh -noprofile
& (Get-Command Write-Host) "text"

Expected behavior

The text is written to host by calling the Write-Host cmdlet via the CommandInfo object (as it is working in Windows PowerShell, and I'm pretty sure older versions of pwsh as well).

text

Actual behavior

ArgumentNullException: Value cannot be null. (Parameter 'key')

Error details from Get-Error -Last 1:

Exception             :
    Type       : System.ArgumentNullException
    Message    : Value cannot be null. (Parameter 'key')
    ParamName  : key
    TargetSite :
        Name          : ThrowKeyNullException
        DeclaringType : System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue]
        MemberType    : Method
        Module        : System.Collections.Concurrent.dll
    StackTrace :
   at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNullException()
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at System.Management.Automation.CommandProcessor.ConstructInstance(Type type)
   at System.Management.Automation.CommandProcessor.Init(CmdletInfo cmdletInformation)
    Source     : System.Collections.Concurrent
    HResult    : -2147467261
CategoryInfo          : NotSpecified: (:) [], ArgumentNullException
FullyQualifiedErrorId : System.ArgumentNullException
InvocationInfo        :
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : -1
    Line             : & (gcm w*st) a
    PositionMessage  : At line:1 char:1
                       + & (gcm w*st) a
                       + ~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

Reproduces both in a clean 7.0.1 install as well as the most recent preview release (7.1-preview3). Also reproduces under 7.3.0-preview4 and 7.2.4.

Name                           Value
----                           -----
PSVersion                      7.0.1
PSEdition                      Core
GitCommitId                    7.0.1
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name                           Value
----                           -----
PSVersion                      7.1.0-preview.3
PSEdition                      Core
GitCommitId                    7.1.0-preview.3
OS                             Darwin 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar  4 22:28:40 PST 2020; root:xnu-6153…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Name                           Value
----                           -----
PSVersion                      7.2.4
PSEdition                      Core
GitCommitId                    7.2.4
OS                             Darwin 21.4.0 Darwin Kernel Version 21.4.0: Fri Mar 18 00:45:05 PDT 2022; root:xnu-8020.101…
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions