-
Notifications
You must be signed in to change notification settings - Fork 472
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
Comments
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:
|
I've executed that command in the Terminal and got an error message, that
the module file psm1 couldn't be loaded.
I've also included that command on top of the psm1 file, but with no
results.
Of couse, I've restarted VSCode every time.
2018-05-21 16:27 GMT+02:00 Tyler James Leonhardt <notifications@github.com>:
… 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
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1329 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Akt8RGDTLqU-anfXkNpMPc5hO1mMif9pks5t0s67gaJpZM4UGjN8>
.
|
FYI: In my script, which uses my module and its class, I have to refrerence
it with "using module '.\nameOfManifest.psd1'"
2018-05-21 23:25 GMT+02:00 Andreas H <andreashansberg@gmail.com>:
… I've executed that command in the Terminal and got an error message, that
the module file psm1 couldn't be loaded.
I've also included that command on top of the psm1 file, but with no
results.
Of couse, I've restarted VSCode every time.
2018-05-21 16:27 GMT+02:00 Tyler James Leonhardt ***@***.***
>:
> 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
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#1329 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/Akt8RGDTLqU-anfXkNpMPc5hO1mMif9pks5t0s67gaJpZM4UGjN8>
> .
>
|
Sorry, I was wrong, my fault:
Because I've included that command on top of the psm1 file AND then ran the
command in the Terminal, I've created that infinit module loading loop
error.
The command "Import-Module manifest.psd1" works.
I just have to edit the psm1 file once a little and the errors disappear.
2018-05-21 23:27 GMT+02:00 Andreas H <andreashansberg@gmail.com>:
… FYI: In my script, which uses my module and its class, I have to
refrerence it with "using module '.\nameOfManifest.psd1'"
2018-05-21 23:25 GMT+02:00 Andreas H ***@***.***>:
> I've executed that command in the Terminal and got an error message, that
> the module file psm1 couldn't be loaded.
> I've also included that command on top of the psm1 file, but with no
> results.
> Of couse, I've restarted VSCode every time.
>
> 2018-05-21 16:27 GMT+02:00 Tyler James Leonhardt <
> ***@***.***>:
>
>> 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
>>
>> —
>> You are receiving this because you authored the thread.
>> Reply to this email directly, view it on GitHub
>> <#1329 (comment)>,
>> or mute the thread
>> <https://github.com/notifications/unsubscribe-auth/Akt8RGDTLqU-anfXkNpMPc5hO1mMif9pks5t0s67gaJpZM4UGjN8>
>> .
>>
>
>
|
It's best practice to do something like this: If you put your |
sorry, but you haven't read my last mails carefully, I wrote " I have to
refrerence it with "using module '.\nameOfManifest.psd1'" "
and that wouldn't work without referencing the psm1 file in the manifest.
And because I use a class in the psm1 file, I must use "using" and can't
use "Import-Module"
but thanks for the help
2018-05-21 23:42 GMT+02:00 Tyler James Leonhardt <notifications@github.com>:
… 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.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1329 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Akt8RHUfkHglUnQcvyU10Hn-imM2lSCbks5t0zTagaJpZM4UGjN8>
.
|
But what about the solution for the original issue ?
I don't want runt 'Import-Module manifest.psd1" in the terminal every time
after VSCode startet.
And I have to restart VSCode after EVERY debug run, because it's caching
the class code and other debugging issues ....
2018-05-22 12:55 GMT+02:00 Andreas H <andreashansberg@gmail.com>:
… sorry, but you haven't read my last mails carefully, I wrote " I have to
refrerence it with "using module '.\nameOfManifest.psd1'" "
and that wouldn't work without referencing the psm1 file in the manifest.
And because I use a class in the psm1 file, I must use "using" and can't
use "Import-Module"
but thanks for the help
2018-05-21 23:42 GMT+02:00 Tyler James Leonhardt ***@***.***
>:
> 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.
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#1329 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/Akt8RHUfkHglUnQcvyU10Hn-imM2lSCbks5t0zTagaJpZM4UGjN8>
> .
>
|
@madmidi This is an issue with the PowerShell parser. The ideal workflow is that you include a 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. |
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. |
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. |
Windows 10 x64 1709
1.23.1
1.7.0
$PSVersionTable
:code -v:
1.23.1 d0182c3417d225529c6d5ad24b7572815d0de9ac x64
$pseditor.EditorServicesVersion:
1 7 0 0
code --list-extensions --show-versions:
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:
TIA
best regards
The text was updated successfully, but these errors were encountered: