Skip to content

[System.Management.Automation.CompletionCompleters]::CompleteFilename("") throws NullReferenceException #26277

Closed

Description

@teramako

Prerequisites

Steps to reproduce

on 7.6.0-preview.5

[System.Management.Automation.CompletionCompleters]::CompleteFilename("") throws NullReferenceException

Expected behavior

should returns CompletionResult

Actual behavior

PS> [System.Management.Automation.CompletionCompleters]::CompleteFilename("")
MethodInvocationException: Exception calling "CompleteFilename" with "1" argument(s): "Object reference not set to an instance of an object."

Error details

PS> Get-Error -newest 1

Exception             :
    Type           : System.Management.Automation.MethodInvocationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Exception calling "CompleteFilename" with "1" argument(s): "Object reference not set to an instance of an object."
            HResult : -2146233087
        CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : NullReferenceException
        InvocationInfo        :
            ScriptLineNumber : 1
            OffsetInLine     : 1
            HistoryId        : 1
            Line             : [System.Management.Automation.CompletionCompleters]::CompleteFilename("")
            Statement        : [System.Management.Automation.CompletionCompleters]::CompleteFilename("")
            PositionMessage  : At line:1 char:1
                               + [System.Management.Automation.CompletionCompleters]::CompleteFilename …
                               + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    TargetSite     :
        Name          : ConvertToMethodInvocationException
        DeclaringType : [System.Management.Automation.ExceptionHandlingOps]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Message        : Exception calling "CompleteFilename" with "1" argument(s): "Object reference not set to an instance of an object."
    Data           :
        System.Management.Automation.Interpreter.InterpretedFrameInfo, System.Management.Automation, Version=7.6.0.5, Culture=neutral, PublicKeyToken=31bf3856ad364e35 : <ScriptBlock>

    InnerException :
        Type       : System.NullReferenceException
        TargetSite :
            Name          : CompleteFilename
            DeclaringType : [System.Management.Automation.CompletionCompleters]
            MemberType    : Method
            Module        : System.Management.Automation.dll
        Message    : Object reference not set to an instance of an object.
        Source     : System.Management.Automation
        HResult    : -2147467261
        StackTrace :
   at System.Management.Automation.CompletionCompleters.CompleteFilename(CompletionContext context, Boolean containerOnly, HashSet`1 extension)
   at CallSite.Target(Closure, CallSite, Type, String)
    Source         : System.Management.Automation
    HResult        : -2146233087
    StackTrace     :
   at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo)
   at CallSite.Target(Closure, CallSite, Type, String)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
   at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
FullyQualifiedErrorId : NullReferenceException
InvocationInfo        :
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 1
    Line             : [System.Management.Automation.CompletionCompleters]::CompleteFilename("")
    Statement        : [System.Management.Automation.CompletionCompleters]::CompleteFilename("")
    PositionMessage  : At line:1 char:1
                       + [System.Management.Automation.CompletionCompleters]::CompleteFilename …
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.0-preview.5
PSEdition                      Core
GitCommitId                    7.6.0-preview.5
OS                             Ubuntu 24.04.3 LTS
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Activity

  1. iSazonov commented on Oct 23, 2025

    @iSazonov
    Collaborator

    teramako (@teramako) Thanks! I can confirm the issue

    Exception             :
        Type           : System.Management.Automation.MethodInvocationException
        ErrorRecord    :
            Exception             :
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : Exception calling "CompleteFilename" with "1" argument(s): "Object reference not set to an
    instance of an object."
                HResult : -2146233087
            CategoryInfo          : NotSpecified: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : NullReferenceException
            InvocationInfo        :
                ScriptLineNumber : 1
                OffsetInLine     : 1
                HistoryId        : 3
                Line             : [System.Management.Automation.CompletionCompleters]::CompleteFilename("")
                Statement        : [System.Management.Automation.CompletionCompleters]::CompleteFilename("")
                PositionMessage  : At line:1 char:1
                                   + [System.Management.Automation.CompletionCompleters]::CompleteFilename …
                                   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                CommandOrigin    : Internal
            ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
        TargetSite     :
            Name          : ConvertToMethodInvocationException
            DeclaringType : [System.Management.Automation.ExceptionHandlingOps]
            MemberType    : Method
            Module        : System.Management.Automation.dll
        Message        : Exception calling "CompleteFilename" with "1" argument(s): "Object reference not set to an
    instance of an object."
        Data           :
            System.Management.Automation.Interpreter.InterpretedFrameInfo, System.Management.Automation, Version=7.6.0.0,
    Culture=neutral, PublicKeyToken=31bf3856ad364e35 : <ScriptBlock>
    
        InnerException :
            Type       : System.NullReferenceException
            TargetSite :
                Name          : CompleteFilename
                DeclaringType : [System.Management.Automation.CompletionCompleters]
                MemberType    : Method
                Module        : System.Management.Automation.dll
            Message    : Object reference not set to an instance of an object.
            Source     : System.Management.Automation
            HResult    : -2147467261
            StackTrace :
       at System.Management.Automation.CompletionCompleters.CompleteFilename(CompletionContext context, Boolean
    containerOnly, HashSet`1 extension) in PowerShell\src\System.Management.Automati
    on\engine\CommandCompletion\CompletionCompleters.cs:line 4583
       at System.Management.Automation.CompletionCompleters.CompleteFilename(String fileName) in C:\Users\sie\Documents\Git
    Hub\iSazonov\PowerShell\src\System.Management.Automation\engine\CommandCompletion\CompletionCompleters.cs:line 4440
       at CallSite.Target(Closure, CallSite, Type, String)
        Source         : System.Management.Automation
        HResult        : -2146233087
        StackTrace     :
       at System.Management.Automation.ExceptionHandlingOps.ConvertToMethodInvocationException(Exception exception, Type
    typeToThrow, String methodName, Int32 numArgs, MemberInfo memberInfo) in PowerSh
    ell\src\System.Management.Automation\engine\runtime\Operations\MiscOps.cs:line 2167
       at CallSite.Target(Closure, CallSite, Type, String)
       at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
       at System.Management.Automation.Interpreter.DynamicInstruction`3.Run(InterpretedFrame frame) in C:\Users\sie\Documen
    ts\GitHub\iSazonov\PowerShell\src\System.Management.Automation\engine\interpreter\DynamicInstructions.Generated.cs:line
     169
       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) in C:\Users\
    sie\Documents\GitHub\iSazonov\PowerShell\src\System.Management.Automation\engine\interpreter\ControlFlowInstructions.cs
    :line 355
    CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    FullyQualifiedErrorId : NullReferenceException
    InvocationInfo        :
        ScriptLineNumber : 1
        OffsetInLine     : 1
        HistoryId        : 3
        Line             : [System.Management.Automation.CompletionCompleters]::CompleteFilename("")
        Statement        : [System.Management.Automation.CompletionCompleters]::CompleteFilename("")
        PositionMessage  : At line:1 char:1
                           + [System.Management.Automation.CompletionCompleters]::CompleteFilename …
                           + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        CommandOrigin    : Internal
    ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    
  2. iSazonov commented on Oct 23, 2025

    @iSazonov
    Collaborator

    MartinGC94 It seems it comes from #20017. Could you please look?

    (For test I asked Copilot to create fix. See #26286)

  3. daxian-dbw commented on Oct 23, 2025

    @daxian-dbw
    Member

    Thanks for reporting this regression. I will submit a fix soon.

  4. microsoft-github-policy-service commented on Oct 23, 2025

    @microsoft-github-policy-service
    Contributor

    📣 Hey @teramako (@teramako), how did we do? We would love to hear your feedback with the link below! 🗣️

    🔗 https://aka.ms/PSRepoFeedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions