-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UseShouldProcessCorrectly Unable to find type #1217
Comments
Interesting, thanks for reporting it. I have seen similar problems before but in much more complex scenarios. Can you repro as well when you are already in the PowerShell shell and then call Invoke-ScriptAnalyzer? The PRs that you mentioned brought back caching and improved it, which is something we'd not revert. I have talked with members of the PS team about similar exceptions that we sometimes see with PSSA and we concluded that this is probably not a race condition but a different multi-threading problem: |
@bergmeister thanks for the reply, here are my replies to your questions;
Yes I can, it just appears to be more frequent if I do it outside of an interactive interpreter but that honestly could just be random luck.
Totally fine, didn't mean to say that they should be reverted, was just pointing them out as the potential changes that introduced the problem to help with investigating what may need to be done.
Unfortunately it doesn't help, I still get the same error with this branched checkout of PSScriptAnalyzer. |
Thanks for the detailed feedback, I think in this we should try calling the properties on the |
I have exactly the same problem with script, that contains some ActiveDirectory commands. Strange is, that it causes error only in VSC editor (not in PS console). And super strange is, that if I run Invoke-ScriptAnalyzer with -verbose it stills output the error, but not as terminating one. (I call the command in pre-commit git hook, PS script) Error is: |
I just hit this today. The problem occurs here: This is really a PowerShell bug, since it should be able to provide us attributes on a CommandInfo object without having to load everything. If I can repro it in 7, we might be able to fix it in 7.1. We should do the following:
|
I think it's one of the many thread safety issues that PowerShell has, similar to PowerShell/PowerShell#9889 |
In this case I suspect it's a case of having a command info for a function without having loaded the module and therefore the types it depends on, but I could be wrong. In any case, we can't rely on PowerShell to solve it and this is probably somewhere where we should do everything we can not to depend on the |
Steps to reproduce
Invoke-Pester
Install Pester with
Install-Module -Name Pester
Then run
pwsh -Command 'Invoke-ScriptAnalyzer -Path test.ps1'
multiple times until you get the errorExpected behavior
Passes with no exception
Actual behavior
It usually succeeds normally but can sometimes fail with the exception
I've found that if I do
pwsh -Command 'Import-Module Pester; Invoke-PSScriptAnalyzer -Path ...
I cannot replicate the issue and the Pester types have been fully loaded. What is weird is that this only sometimes occurs which tells me theUseShouldProcessCorrectly
rule is parsing module commands but there's a race condition where the type is not fully loaded by the time it tries to scan the attributes.Some things I've tried
Import-Module -Name Pester
before calling PSSA, no more error but I don't want to do this for all modules in the codeMy guess is that because this is an error only in the new version, the changes in #1074 or #1166 could be the cause.
Environment data
The text was updated successfully, but these errors were encountered: