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.

Error: The scope number '7' exceeds the number of active scopes. Parameter name: ScopeID

See original GitHub issue

System Details

### VSCode version: 1.34.0-insider 56f1b4795fed05677eb82a21dac4fc1ab62d747b
x64

### VSCode extensions:
ms-vscode.powershell@1.12.0
ms-vscode.powershell-preview@2.0.1
ritwickdey.LiveServer@5.5.1


### PSES version: 2.0.0.0

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      5.1.14409.1018
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1018
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Issue Description

Sometimes I receive the following error:

[-] should be green 15.49s ValidationMetadataException: The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. ParameterBindingValidationException: Cannot validate argument on parameter ‘Message’. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. at <ScriptBlock>, S:\Test\Script.ps1: line 5

Script.ps1

$Error.Clear()

if ($Error) {
    $Error.ForEach( {
            Write-EventLog @EventErrorParams -Message $_.Exception.Message
        })
}

Script.Tests.ps1

$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'

$Error.Clear()

Describe $sut {
    Mock Write-EventLog

    It 'should be green' {
        ."$here\$sut"
        $Error | Should -BeNullOrEmpty
    }
    In $TestDrive {
        Describe 'Test' {
            It 'should be green' {
                ."$here\$sut"
                $Error | Should -BeNullOrEmpty
            }
        }
    }
}

This does not always happen and it took me a long time to figure out that this only happens in VS Code and never in the PowerShell ISE. To narrow it further down the behavior can be consistently reproduced when setting a breakpoint at the line if ($Error).

When consulting the array of $Error at the breakpoint the following is shown: image

I don;t know why this happens, but it could be related to #66. I’m using the PowerShell Preview 2.0.1.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:18 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
johndogcommented, Aug 2, 2019

I might suggest that the debugger should always explicitly provide -ErrorVariable for every command it runs, so that its errors (designed or not) are always kept in a sandbox…

0reactions
samjones3commented, Mar 22, 2022

There is a StackOverflow thread (or more) asking about this sphere: https://stackoverflow.com/q/71562738/147637

Read more comments on GitHub >

github_iconTop Results From Across the Web

Powershell : The scope number '4' exceeds the number of ...
I hit this very randomly, my ps session stops and I get error in automation. Exception: The scope number '4' exceeds the number...
Read more >
Pipeline variable - scope number exceeded
It gaves me no record and debug displays an error: The scope number '1' exceeds the number of active scopes.Parameter name: scopeIDActual ......
Read more >
Error: The scope number '7' exceeds the number of active scopes ...
Error : The scope number '7' exceeds the number of active scopes. Parameter name: ScopeID.
Read more >
Something that might be useful - narkive
ERROR : Get-Variable : The scope number '4' exceeds the number of active scopes. ERROR: Parameter name: scopeID. ERROR: Actual value was 4....
Read more >
Single sensor to display DHCP scope status
I named it dhcpscopevalue.ps1 and placed it into the Custom Sensor/EXE ... on the number of Scopes foreach ($scope in $dhcpscopes) { $scopeid...
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