Skip to content

Breaking Change in using syntax limits the language #25060

@StartAutomating

Description

@StartAutomating

A pull request for version 7.5 restricted the language syntax - #21162

This limits the syntax of PowerShell from its current surface area, which is especially troublesome for those of us who use the flexible syntax of PowerShell.

In this particular case, there have been modules using this format to describe container relationships.

Specifically, Container.init.ps1 files have used using to describe the base layer, and Container.start.ps1 files use this to describe that container is being started. One example is here, in the Container.init.ps1 for ugit.

Because of this breaking change all containers built with this technique also break . All of the builds that produce these containers also are broken.

This approach has been "in the wild" for approximately a year, since it was first introduced at the PowerShell Summit in two talks (Rocking Docker with PowerShell, Mastering Making Modules).

This approach has also been shown directly to various members of the PowerShell Team.

Additional specced future use has been to describe names prefixing names of a function (for example, making using namespace http:// make every function within the file prefixed with http://)

There should be no restriction on using syntax, and future constraints of the PowerShell language syntax should be very carefully considered

Prerequisites

Steps to reproduce

To reproduce this issue, simply type using namespace mcr.microsoft.com/powershell at the top of a file.

A simple repro:

'using namespace mcr.microsoft.com/powershell' > useThis.ps1
.\useThis.ps1

Expected behavior

`using namespace mcr.microsoft.com/powershell` runs without error, allowing the metadata in the file to be easily queried and accessed.

Actual behavior

`using namespace mcr.microsoft.com/powershell` yields:

` The specified namespace in the 'using' statement contains invalid characters.`

Error details

Exception             : 
    Type        : System.Management.Automation.ParseException
    Errors      : 
        Extent  : mcr.microsoft.com/powershell
        ErrorId : InvalidNamespaceValue
        Message : The specified namespace in the 'using' statement contains invalid characters.
    Message     : At C:\Users\James\useThis.ps1:1 char:17
                  + using namespace mcr.microsoft.com/powershell
                  +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                  The specified namespace in the 'using' statement contains invalid characters.
    ErrorRecord : 
        Exception             : 
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : At C:\Users\James\useThis.ps1:1 char:17
                      + using namespace mcr.microsoft.com/powershell
                      +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                      The specified namespace in the 'using' statement contains invalid characters.
            HResult : -2146233087
        CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : InvalidNamespaceValue
        InvocationInfo        : 
            ScriptLineNumber : 1
            OffsetInLine     : 17
            HistoryId        : 7
            ScriptName       : C:\Users\James\useThis.ps1
            Line             : using namespace mcr.microsoft.com/powershell
                               
            Statement        : mcr.microsoft.com/powershell
            PositionMessage  : At C:\Users\James\useThis.ps1:1 char:17
                               + using namespace mcr.microsoft.com/powershell
                               +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            PSScriptRoot     : C:\Users\James
            PSCommandPath    : C:\Users\James\useThis.ps1
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    TargetSite  : 
        Name          : Create
        DeclaringType : [System.Management.Automation.ScriptBlock]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Data        : System.Collections.ListDictionaryInternal
    Source      : System.Management.Automation
    HResult     : -2146233087
    StackTrace  : 
   at System.Management.Automation.ScriptBlock.Create(Parser parser, String fileName, String fileContents)
   at System.Management.Automation.ExternalScriptInfo.ParseScriptContents(Parser parser, String fileName, String fileContents, Nullable`1 definingLanguageMode)
   at System.Management.Automation.ExternalScriptInfo.get_ScriptBlock()
   at System.Management.Automation.CommandDiscovery.CreateCommandProcessorForScript(ExternalScriptInfo scriptInfo, ExecutionContext context, Boolean useNewScope, SessionStateInternal sessionState)
   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(CommandInfo commandInfo, CommandOrigin commandOrigin, Nullable`1 useLocalScope, SessionStateInternal sessionState)
   at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1 useLocalScope)
   at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)
   at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements, CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : ParserError: (:) [], ParseException
FullyQualifiedErrorId : InvalidNamespaceValue
InvocationInfo        : 
    ScriptLineNumber : 1
    OffsetInLine     : 17
    HistoryId        : 7
    ScriptName       : C:\Users\James\useThis.ps1
    Line             : using namespace mcr.microsoft.com/powershell
                       
    Statement        : mcr.microsoft.com/powershell
    PositionMessage  : At C:\Users\James\useThis.ps1:1 char:17
                       + using namespace mcr.microsoft.com/powershell
                       +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    PSScriptRoot     : C:\Users\James
    PSCommandPath    : C:\Users\James\useThis.ps1
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

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

Visuals

Image

Will attach more issues as I fix the dozens of breaking changes this introduced.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution-By DesignThe reported behavior is by design.WG-Enginecore PowerShell engine, interpreter, and runtimeWG-Languageparser, language semanticsWG-ReviewedA Working Group has reviewed this and made a recommendation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions