8000 ConvertFrom-Markdown throws Null Exception when run inside Runspace · Issue #9390 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

ConvertFrom-Markdown throws Null Exception when run inside Runspace #9390

@Badgerati

Description

@Badgerati

When running the ConvertFrom-Markdown command from within a new runspace, the command throws a null reference exception.

Steps to reproduce

$pool = [runspacefactory]::CreateRunspacePool(1, 2, $Host)
$pool.Open()

$ps = [powershell]::Create()
$ps.RunspacePool = $pool
$ps.AddScript({
    try {
        '# test' | ConvertFrom-Markdown | Out-Default
    }
    catch {
        $_ | Out-Default
    }
}) | Out-Null

$ps.Invoke()
$ps.Dispose()

Expected behavior

The command should return a MarkdownInfo object

Actual behavior

The command throws a null reference exception:

ConvertFrom-Markdown : Object reference not set to an instance of an object.
At line:3 char:21
+         '# test' | ConvertFrom-Markdown | Out-Default
+                     ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [ConvertFrom-Markdown], NullReferenceException
+ FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.ConvertFromMarkdownCommand

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Linux 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

(note: the same happens on Windows, too)

Notes

Looking into the code, it seems to be caused by the following line:

_mdOption = this.CommandInfo.Module.SessionState.PSVariable.GetValue("PSMarkdownOptionInfo", new PSMarkdownOptionInfo()) as PSMarkdownOptionInfo;

The this.CommandInfo.Module is null when running within a new runspace. The line appears to create a default PSMarkdownOptionInfo object if the session variable is null - so if the module is null maybe create a default PSMarkdownOptionInfo?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0