Skip to content

CommandInfo.ResolveParameter throws NullReferenceException sometimes #13127

@rjmholt

Description

@rjmholt

From PowerShell/PSScriptAnalyzer#1538.

PSScriptAnalyzer tries to get the value of Export-ModuleMember's parameters by calling the CommandInfo.ResolveParameter() call here.

This calls into PowerShell here:

/// <summary>
/// Resolves a full, shortened, or aliased parameter name to the actual
/// cmdlet parameter name, using PowerShell's standard parameter resolution
/// algorithm.
/// </summary>
/// <param name="name">The name of the parameter to resolve.</param>
/// <returns>The parameter that matches this name.</returns>
public ParameterMetadata ResolveParameter(string name)
{
MergedCommandParameterMetadata merged = GetMergedCommandParameterMetadataSafely();
MergedCompiledCommandParameter result = merged.GetMatchingParameter(name, true, true, null);
return this.Parameters[result.Parameter.Name];
}

As with various other CommandInfo members, this appears not to be threadsafe and the call sometimes throws an NRE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-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