I have a script like this, in a classes.psm1
file:
class A {
A([string] s) { }
}
class B : A {
B([string] s) : base($s)
}
Then I try to import it in a .ps
file:
using module classes.psm1
class C : B {
[A] $p
C([string] s) : base($s) {
$this.p = A::new($s)
}
}
Above, B is known, but not A, throwing Unable to find type [A]
.
How is it possible to work with both classes in the latter script?
Note: Moving C in the same module as A and B makes it unknown in the latter script.
I have a script like this, in a classes.psm1
file:
class A {
A([string] s) { }
}
class B : A {
B([string] s) : base($s)
}
Then I try to import it in a .ps
file:
using module classes.psm1
class C : B {
[A] $p
C([string] s) : base($s) {
$this.p = A::new($s)
}
}
Above, B is known, but not A, throwing Unable to find type [A]
.
How is it possible to work with both classes in the latter script?
Note: Moving C in the same module as A and B makes it unknown in the latter script.
Basically, @Destroy666 is right, although I've come from a similar issue also posted here.
Yet, it turns out the code is right, but the Powershell seems to have problems with processing it correctly - but I am a newbie with Powershell, so I can't be sure now. So, after trying and assessing, I've found that closing and re-opening Powershell clears some cache or interprets the code from scratch, so it works fine. Also, right now it behaves in a way that it needs a Powershell closing/re-opening each time the base class (called A above) code is changed, otherwise false positive errors occur. To me, although it looks to be related to programming, this knowledge may be useful to any system admin that writes some Powershell code like this.