vscode-powershell
vscode-powershell copied to clipboard
PS Class type not found error with using module
System Details
System Details Output
### VSCode version: 1.47.3 91899dcef7b8110878ea59626991a18c8a6a1b3e x64
### VSCode extensions:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
### PSES version: 2.3.0.0
### PowerShell version:
Name Value
---- -----
PSVersion 7.1.0-preview.5
PSEdition Core
GitCommitId 7.1.0-preview.5
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Description
PS Class with using module statement throws type not found. If in the integrated PS console I run using module X
and then remove and add back the using statements the error will away.
It looks as though VS code is not running the using statements while editing the script.
Expected Behaviour
Open a class file with types residing in a module and no type not found error is thrown.
Actual Behaviour
Type not found until manually running using statements in integrated console.
Attached Logs
Follow the instructions in the troubleshooting docs about capturing and sending logs.
@ThomasNieto can you provide an example?
using module
statements are notoriously finicky when it comes to static analysis.
@SeeminglyScience Here is a way to reproduce:
I have a classtest.dll which is the RootModule
in the Test
module.
namespace ClassTest.Test
{
public class Animal
{
public string Name { get; set; }
}
}
The animal class will throw a type not found error. To get it to work I have to do the following:
- In integrated console run:
using module Test
- Cut and paste either using statement.
- Animal type no longer has the error
This workflow can be reproduced over and over by restarting the integrated console.
using module Test
using namespace ClassTest.Test
class Dog : Animal
{
}
Removing the using namespace doesn't make a difference.
using module Test
class Dog : ClassTest.Test.Animal
{
}
Yeah that's one of the situations where it doesn't work, binary modules. Here's the issue tracking it: PowerShell/PowerShell#6653 (sort of, that needs to come first but even then there's a lot of obstacles to jump from using assembly
to using module
for static analysis of assemblies)
I get having to run using module in the console to load the assemblies but why does it require redefining the using statements in the script?
You sure it isn't just any edit? PSSA (where those warnings come from kinda sorta) wouldn't be ran again until there's an edit of some sort.
Yeah, any edit seems to do.
There isn't much we can do in the PowerShell extension, something that would be nice to have is re-running diagnostics when a module is loaded, but PowerShell doesnt have an event for that and likely wont in the intermediate future leaving us without many options
@andschwa @SeeminglyScience there currently is a situation where we get both the "unable to find type" and the PSScriptAnalyzer "Ignoring TypeNotFound" info. Maybe if we detect both of these we can silently suppress the error Problem and only present the information warning?
If so it may be worth reopening this issue to address.
Thank you for your comment, but please note that this issue has been closed for over a week. For better visibility, consider opening a new issue with a link to this instead.
Just FYI @JustinGrote I'm adding you to the bot's ignore list for it's auto responder lol. Setting it to exclude "collaborators" and up now.
To the issue at hand, I'm not sure! But I can reopen for us to look at again.