Skip to content

How to suppress TypeNotFound for a powershell class in VSCode #1584

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

Closed
plastikfan opened this issue Sep 9, 2020 · 2 comments
Closed

How to suppress TypeNotFound for a powershell class in VSCode #1584

plastikfan opened this issue Sep 9, 2020 · 2 comments

Comments

@plastikfan
Copy link

I found another issue on stackoverflow that was raised a while ago that is the same issue but does not have a solution: https://stackoverflow.com/questions/51918645/how-to-suppress-powershell-unable-to-find-type-typename-message

controller.ps1:

class Controller {
  [System.Collections.Hashtable]$_passThru;

  Controller(
    [System.Collections.Hashtable]$passThru
  ) {
    $this._passThru = $passThru;
  }
}

foreachcontroller.ps1

[Diagnostics.CodeAnalysis.SuppressMessageAttribute('TypeNotFound', '')]
class ForeachController : Controller {
  ForeachController(
    [System.Collections.Hashtable]$passThru
  ) {

  }
}

VScode shows this error:

Ignoring 'TypeNotFound' parse error on type 'Controller'. Check if the specified type is correct. This can also be due the type not being known at parse time due to types imported by 'using' statements.

As you can see, I attempted to suppress th message in foreachcontroller.ps1 (the reference to the Controller class), but this has no effect.

I need to supress the message in 2 contexts. Once when I invoke the script analyzer on the command line, then I also need to suppress the scriptanalyzer built into VSCode to prevent the dreaded red squiggly line from showing up in the text editor.

I can't find relevant documentation for this in the githib repo or elsewhere, so how do I supress this message. When I go to build the module that contains this code, there is no build error, but I need to supress this error to prevent VSC from flagging this none issue. There is no entry for the TypeNotFound rule in the rule documentation.

thanks.

@ghost ghost added the Needs: Triage 🔍 label Sep 9, 2020
@plastikfan
Copy link
Author

plastikfan commented Sep 9, 2020

I also tried to add a PSScriptAnalyzer.psd1 file in the root of the repo:

@{
  Severity     = @('Error', 'Warning')
  ExcludeRules = @('TypeNotFound')
}

needless to say, that failed too.

Perhaps, because this is actually an error, it can't be suppressed? Stilll need to be suppressed though, as in the built artefact, it is not an error as the type can be resolved.

@rjmholt
Copy link
Contributor

rjmholt commented Sep 9, 2020

See #1041

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants