Skip to content

NullReferenceException in Get-Command #9396

@rkeithhill

Description

@rkeithhill

Steps to reproduce

# This throws:
PS> get-command "less `"-PsPage %db?B of %D:`"" -ErrorAction Ignore
get-command : Object reference not set to an instance of an object.
# This doesn't:
PS> get-command "less `"-PsPage %db?B of %D`"" -ErrorAction Ignore

It looks like the D: in the string looks like a path??

Expected behavior

This command shouldn't throw a terminating error given this input.

Actual behavior

It throws this exception:

PSMessageDetails      :
Exception             : System.NullReferenceException: Object reference not set to an instance of an object.
                           at System.Management.Automation.CommandSearcher.GetNextFromPath() in C:\Users\Keith\GitHub\r
                        keithhill\PowerShell\src\System.Management.Automation\engine\CommandSearcher.cs:line 477
                           at System.Management.Automation.CommandSearcher.ProcessBuiltinScriptState() in C:\Users\Keit
                        h\GitHub\rkeithhill\PowerShell\src\System.Management.Automation\engine\CommandSearcher.cs:line
                        292
                           at System.Management.Automation.CommandSearcher.MoveNext() in C:\Users\Keith\GitHub\rkeithhi
                        ll\PowerShell\src\System.Management.Automation\engine\CommandSearcher.cs:line 191
                           at
                        Microsoft.PowerShell.Commands.GetCommandCommand.FindCommandForName(SearchResolutionOptions
                        options, String commandName, Boolean isPattern, Boolean emitErrors, Int32& currentCount,
                        Boolean& isDuplicate) in C:\Users\Keith\GitHub\rkeithhill\PowerShell\src\System.Management.Auto
                        mation\engine\GetCommandCommand.cs:line 887
                           at Microsoft.PowerShell.Commands.GetCommandCommand.AccumulateMatchingCommands(IEnumerable`1
                        commandNames) in C:\Users\Keith\GitHub\rkeithhill\PowerShell\src\System.Management.Automation\e
                        ngine\GetCommandCommand.cs:line 759
                           at Microsoft.PowerShell.Commands.GetCommandCommand.AccumulateMatchingCommands() in C:\Users\
                        Keith\GitHub\rkeithhill\PowerShell\src\System.Management.Automation\engine\GetCommandCommand.cs
                        :line 700
                           at Microsoft.PowerShell.Commands.GetCommandCommand.ProcessRecord() in C:\Users\Keith\GitHub\
                        rkeithhill\PowerShell\src\System.Management.Automation\engine\GetCommandCommand.cs:line 421
                           at System.Management.Automation.Cmdlet.DoProcessRecord() in C:\Users\Keith\GitHub\rkeithhill
                        \PowerShell\src\System.Management.Automation\engine\cmdlet.cs:line 173
                           at System.Management.Automation.CommandProcessor.ProcessRecord() in C:\Users\Keith\GitHub\rk
                        eithhill\PowerShell\src\System.Management.Automation\engine\CommandProcessor.cs:line 386
TargetObject          :
CategoryInfo          : NotSpecified: (:) [Get-Command], NullReferenceException
FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.GetCommandCommand
ErrorDetails          :
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.0-rc.1
PSEdition                      Core
GitCommitId                    6.2.0-rc.1-167-ge9ffbe5cf27ad6461607fcf4bc69258652a88d33
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

Interesting this shows 6.2.0-rc.1 since I'm building off of the latest on master. BTW this is a regression from 6.1.0 where this did not throw an NRE.

Metadata

Metadata

Assignees

Labels

Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions