question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PowerShell Integrated Console: "Value cannot be null" for missing mandatory parameter when debugging

See original GitHub issue

Issue Type: Bug

Steps to reproduce

Create a .ps1 script file with the following contents:

class MyNewClass {
    [string] $DummyVar
}

function Get-Details {
    param (
        [Parameter(Mandatory)][MyNewClass] $ClassVar,
        [Parameter(Mandatory)][String] $StringVar
    )
    $ClassVar | Out-Host
}

Get-Details

Run the script from a PowerShell terminal window in VSCode.

Expected behavior

Using an explicit “pwsh” terminal inside VSCode, or an external Windows PowerShell or PowerShell Core shell, the above code gives:

cmdlet Get-Details at command pipeline position 1
Supply values for the following parameters:
ClassVar:

Actual behavior

From the PowerShell Integrated Console, the same script results in:

Value cannot be null.
Parameter name: type
At C:\Users\myuser\Documents\Development\PowerShell\TestParamNull.ps1:14 char:1
+ Get-Details
+ ~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (:) [], ArgumentNullException
+ FullyQualifiedErrorId : System.ArgumentNullException

If I explicitly call “pwsh” from inside this same integrated console, the script then works as expected.

Best guesses are that the issue is occurring when the debugger is involved, or that your readline is choking because it doesn’t know how to request the user enters a custom class?

Environment data

Explicit pwsh

PS> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
PS> $PSHOME
C:\Program Files\PowerShell\6

PowerShell Integrated Console

PS>$PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
PS> $PSHOME
C:\Program Files\PowerShell\6

VSCode PowerShell Debugger Launch Config

        {
            "name": "PowerShell Launch Current File",
            "type": "PowerShell",
            "request": "launch",
            "script": "${file}",
            "args": [],
            "cwd": "${file}"
        }

Extension version: 1.12.1 VS Code version: Code 1.34.0 (a622c65b2c713c890fcf4fbf07cf34049d5fe758, 2019-05-15T21:59:37.030Z) OS version: Windows_NT x64 10.0.17763

System Info
Item Value
CPUs Intel® Core™ i7-7820HQ CPU @ 2.90GHz (8 x 2904)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: enabled
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) undefined
Memory (System) 31.81GB (14.95GB free)
Process Argv
Screen Reader no
VM 0%

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

2reactions
gmckeowncommented, May 20, 2019

Just installed a fresh copy of VSCode Insiders:

Version: 1.35.0-insider (user setup) Commit: a5536b8f5a16a10d859f3dec1e59701671bf069e Date: 2019-05-20T05:17:36.269Z Electron: 3.1.8 Chrome: 66.0.3359.181 Node.js: 10.2.0 V8: 6.6.346.32 OS: Windows_NT x64 10.0.17763

Then installed PowerShell preview 2.0.2

Placed the following into my settings.json:

{
    "terminal.integrated.shell.windows": "c:\\program files\\PowerShell\\6\\pwsh.exe",
    "powershell.powerShellExePath": "C:\\Program Files\\PowerShell\\6\\pwsh.exe"
}

Output was as it was before:

PS> .\TestParamNull.ps1
Value cannot be null.
Parameter name: type
At C:\Users\myuser\Documents\Development\PowerShell\TestParamNull.ps1:14 char:1
+ Get-Details
+ ~~~~~~~~~~~
+ CategoryInfo          : OperationStopped: (:) [], ArgumentNullException
+ FullyQualifiedErrorId : System.ArgumentNullException

Added this to my settings.json:

    "powershell.developer.featureFlags": [ "PSReadLine" ]

And now I get:

PS> .\TestParamNull.ps1

cmdlet Get-Details at command pipeline position 1
Supply values for the following parameters:
ClassVar:

So that does seem pretty conclusive! 😃

1reaction
rjmholtcommented, May 20, 2019

It’s likely that this is fixed in the preview extension using PSReadLine

@TylerLeonhardt just confirmed that this does indeed work in the preview extension

Read more comments on GitHub >

github_iconTop Results From Across the Web

Value cannot be null. Parameter name: connectionString ...
I was missing the letter 's' after the ConnectionString property name in the appsettings.json when using Configuration.
Read more >
Remote PowerShell Error: Value cannot be null - TechNet
For example I am trying to run the New-MailboxExportRequest and I alway get the error "Value cannot be null." If I run the...
Read more >
How to Prevent PowerShell from Prompting on Mandatory ...
How to have PowerShell parameters that are mandatory but don't prompt the user when they are missing, even by pipeline.
Read more >
User and Workspace Settings - Visual Studio Code
The error can be as simple as a missing comma or incorrect setting value. ... of the panel (Terminal, Debug Console, Output, Problems)...
Read more >
Troubleshooting SAML 2.0 federation with AWS
Error: Your request included an invalid SAML response. to logout, click here. Error: RoleSessionName is required in AuthnResponse (service: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found