Skip to content
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

"Type not found" for types from referenced assemblies, used in PowerShell 5.0 classes in a module #1329

Closed
ghost opened this issue May 21, 2018 · 10 comments

Comments

@ghost
Copy link

ghost commented May 21, 2018

  • Operating system name and version: Windows 10 x64 1709
  • VS Code version: 1.23.1
  • PowerShell extension version: 1.7.0
  • Output from $PSVersionTable:
PSVersion                      5.1.16299.431
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.431
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

code -v:
1.23.1 d0182c3417d225529c6d5ad24b7572815d0de9ac x64

$pseditor.EditorServicesVersion:
1 7 0 0

code --list-extensions --show-versions:

johnstoncode.svn-scm@1.29.0
MS-CEINTL.vscode-language-pack-de@1.23.3
ms-vscode.csharp@1.15.2
ms-vscode.PowerShell@1.7.0
ms-vscode.vs-keybindings@0.2.0
wmaurer.change-case@1.0.0
xyz.local-history@1.6.2

Dear Team,
neither your PowerShell extension in VSCode, nor the PoshTools PowerShell extension in VS implement PowerShell 5.0 feature "Classes" very well:

For using .NET types, in a class, from assemblies, you have to load, you've to reference those assemblies in your module's manifest.
If you don't reference them there, PowerShell stops parsing the psm1 file and will not exceute it.
But neither in VSCode, nor in VS, the extension checks the manifest before showing type errors.
Therefor I have 7 "Problems" in my code in VSCode (and VS), because the extensions will not find the types from those external (.NET) assemblies.

This is the bug report for the PoshTools extension in VS:
#https://github.com/adamdriscoll/poshtools/issues/622

Please fix.
You just have to check:

f (type is unknown) -and
   (type used in class) -and
   (class is in a module) -and
   (module has manifest) -and
   (manifest references assemblies)
then
   search in the type declaration of those assmeblies' manifests for the unknow type

TIA
best regards

@TylerLeonhardt
Copy link
Member

Hi there, thanks for the report! If you import the module manifest into the current runspace, do the problems go away? To test this, just run:

ipmo nameOfManifest.psd1

@ghost
Copy link
Author

ghost commented May 21, 2018 via email

@ghost
Copy link
Author

ghost commented May 21, 2018 via email

@ghost
Copy link
Author

ghost commented May 21, 2018 via email

@TylerLeonhardt
Copy link
Member

TylerLeonhardt commented May 21, 2018

It's best practice to do something like this:

If you put your mymodule.psm1 in the NestedModules portion of the manifest.psd1 then you can remove the:
Import-Module manifest.psd1 from your psm1 and just import the psd1 (which will import the psm1 automatically) in your ps1 script.

@ghost
Copy link
Author

ghost commented May 22, 2018 via email

@ghost
Copy link
Author

ghost commented May 22, 2018 via email

@SeeminglyScience
Copy link
Collaborator

@madmidi This is an issue with the PowerShell parser. The ideal workflow is that you include a using assembly ./mylib.dll statement at the top of the ps1 file containing the classes. However, that currently doesn't do anything at parse time, only at runtime.

Check out PowerShell/PowerShell#6653, PowerShell/PowerShell#3641 for more info.

As a workaround until it's fixed in the parser, the next version of PSScriptAnalyzer (the module that generates syntax markers for this extension) has a change by the wonderful @bergmeister to no longer display these type not found errors in it's diagnostics.

@bergmeister
Copy link
Collaborator

bergmeister commented May 22, 2018

PSScriptAnalyzer will release this week (possibly today or tomorrow) and will catch this error and only output a warning instead of re-throwing the parser exception (because it is still able to analyse the rest of the script). Otherwise it is a limitation of PowerShell's parser. There will be some improvements by the PowerShell team but they will not solve all issues because they want to keep the parser purely static to not generate an entry for code injection and vulnerabilities.

@rjmholt
Copy link
Collaborator

rjmholt commented May 22, 2018

Hi @madmidi, this is actually a PowerShell issue, rather than one with the VSCode extension. It's being worked on currently (in PowerShell).

In addition to what @SeeminglyScience linked, have a look at PowerShell/PowerShell#6652.

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

No branches or pull requests

4 participants