Skip to content

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

Closed
@plastikfan

Description

@plastikfan

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.

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