Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Exception occurred while constructing custom validator attribute. #966

Copy link
Copy link
@hubuk

Description

@hubuk
Issue body actions

Steps to reproduce

Run run.ps1
Source code available also here:
https://github.com/hubuk/PSSAReproduction

run.ps1

$env:PSModulePath = "$(Resolve-Path 'Modules');$env:PSModulePath"
Invoke-Analysis

Modules\Common\Common.psm1

function Invoke-WithValidation {
    [CmdletBinding()]
    param (
        [ValidateSomethingAttribute()]
        $Path)
}
class ValidateSomethingAttribute : System.Management.Automation.ValidateArgumentsAttribute {
    [void] Validate([object]$arguments, [System.Management.Automation.EngineIntrinsics]$engineIntrinsics) {
    }
}
Export-ModuleMember -Function '*'

Modules\Main\Main.psm1

function Invoke-Analysis {
    Invoke-ScriptAnalyzer (Join-Path $PSScriptRoot 'Main.psm1')
    Invoke-WithValidation
}
Export-ModuleMember -Function '*'

Expected behavior

No exception shall be reported.

Actual behavior

Exception thrown:

Invoke-ScriptAnalyzer : The following exception occurred while constructing the attribute "ValidateS
omethingAttribute": "There is no Runspace available to run scripts in this thread. You can provide o
ne in the DefaultRunspace property of the System.Management.Automation.Runspaces.Runspace type. The 
script block you attempted to invoke was: "
At F:\GitHub\Leet\PSSAReproduction\Modules\Main\Main.psm1:2 char:5
+     Invoke-ScriptAnalyzer (Join-Path $PSScriptRoot 'Main.psm1')

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.1
PSEdition                      Core
GitCommitId                    v6.0.1
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
> (Get-Module -ListAvailable PSScriptAnalyzer).Version | ForEach-Object { $_.ToString() }
1.16.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.