Skip to content

Help output formatting is not tolerant of StrictMode #10562

@jazzdelightsme

Description

@jazzdelightsme

There is a PowerShell module at work which has a MAML help file (.dll-Help.xml). While the help content seemed to show up okay for some colleagues, it did not show up well for me. I would see content like:

PS C:\Users\jazzdelightsme> open-foo -?

NAME
    Open-Foo

SYNOPSIS
    Opens a new connection to a foo.


SYNTAX
    Open-Foo [-FooName] <string> [<CommonParameters>]

    Open-Foo [<CommonParameters>]

    Open-Foo [<CommonParameters>]

    Open-Foo [<CommonParameters>]


DESCRIPTION
    Lorem ipsum dolor blah blah blah ...


RELATED LINKS

REMARKS
    To see the examples, type: "get-help Open-Foo -examples".
    For more information, type: "get-help Open-Foo -detailed".
    For technical information, type: "get-help Open-Foo -full".


PS C:\Users\jazzdelightsme>

After some troubleshooting, I found that this was due to the fact that I Set-StrictMode -Version Latest in my $profile script. It turns out there is some script run during formatting of help output, and the MAML was perhaps not as complete as it should be. I discovered clues in $error, like:

The property 'required' cannot be found on this object. Verify that the property exists.
At line:1 char:1
+ $optional = $_.required -ne 'true'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
+ FullyQualifiedErrorId : PropertyNotFoundStrict

This can be worked around by filling out the MAML a bit more, but it is rather large, and hand-tweaking MAML is not my idea of a good time. (I'm not sure if the MAML was originally hand-crafted, or some tool was used, or what, but it's quite old.)

Perhaps help formatting could be upgraded to be more tolerant of StrictMode errors?

In fact, it seems that some help formatting script already does this. See here--the script includes a call to Set-StrictMode -Off:

    var RelatedLinksHelpInfoControl = CustomControl.Create()
            .StartEntry()
                .StartFrame(leftIndent: 4)
                    .AddScriptBlockExpressionBinding(StringUtil.Format(@"Set-StrictMode -Off
if (($_.relatedLinks -ne $()) -and ($_.relatedLinks.navigationLink -ne $()) -and ($_.relatedLinks.navigationLink.Length -ne 0))

See also: #6497

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-preview.3
PSEdition                      Core
GitCommitId                    7.0.0-preview.3
OS                             Microsoft Windows 10.0.18985
Platform                       Win32NT
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-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.WG-Interactive-HelpSystemhelp infrastructure and formatting of help

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions