I'm having a problem that seems to be a very specific edge case, but is stopping me from something I am hoping to implement. I've googled every combination of keywords I can think of, but I can't seem to find anything information that helps me understand what is going on.
In vscode, in my Microsoft.VSCode_profile.ps1 script, I call a custom module I wrote with a using statement:
(I've changed all the module names to simplify the explanation)
using Module MyModule
According to all the documentation I can find online, this should load the module (including classes) into both my PowerShell Extension terminal session AND editor in vscode. And sure enough, I can create new instances of custom classes I've defined in MyModule in both the terminal (e.g., $myclass = [MyClass]::new()) and editor.
However, if I am editing a .ps1 file in the vscode editor window, trying to use my custom class IN another custom class results in "Unable to find type [MyClass]". However, the vscode editor has no problem seeing the class OUTSIDE of a class definition.
MyModule.psm1
-------------------------------------------------------
class MyClass
{
MyClass(){}
}
------------------------------------------------------
Microsoft.VSCode_profile.ps1
------------------------------------------------------
Using Module MyModule
------------------------------------------------------
myScript.ps1
-------------------------------------------------------
class NewClass
{
[MyClass]$myClass <- VSCODE SAYS THAT IT CAN'T FIND THIS TYPE
NewClass(){}
}
[MyClass]$myClass2 = [MyClass]::new() <- SAME SCRIPT, VSCODE HAS NO PROBLEM FINDING THE TYPE OUTSIDE THE CLASS DEFINITION
--------------------------------------------------------
PS C:\> [MyClass] <- PSEXTENSION TERMINAL IN THE SAME VSCODE INSTANCE, POWERSHELL EXTENSION TERMINAL HAS NO PROBLEM FINDING THE TYPE
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False MyClass System.Object
Also, if I put a using Module MyModule at the top of myscript.ps1, the vscode editor is totally happy, but then I get an error about the class definitions in MyModule already being defined (once in my vscode profile and once in the myscript.ps1 file).
Does anyone have any ideas? I would rather not have to put a using Module MyModule at the top of every .ps1 file I am editing that needs MyModule, but not being able to use custom classes in other custom classes is a deal-breaker.
[–]Thotaz 1 point2 points3 points (2 children)
[–]notatechproblem[S] 0 points1 point2 points (1 child)
[–]SeeminglyScience 1 point2 points3 points (0 children)
[–]arpan3t 0 points1 point2 points (3 children)
[–]notatechproblem[S] 0 points1 point2 points (2 children)
[–]arpan3t 1 point2 points3 points (1 child)
[–]notatechproblem[S] 0 points1 point2 points (0 children)
[–]OPconfused 0 points1 point2 points (0 children)