Please feel free to provide feedback or file bugs here.

[Bug]: using module that import a script that import classes have unexpected behavior within a class

ClassA.psm1
------------------
class ClassA
{
[string]Execute()
{
return "this is from ClassA"
}
}

ClassB.psm1
------------------
class ClassB
{
[string]Execute()
{
return "this is from ClassB"
}
}

ImportClasses.ps1
-------------------------
using module 'D:\Exemple\Atelier\ClassImportProblem\ClassA.psm1'
using module 'D:\Exemple\Atelier\ClassImportProblem\ClassB.psm1'

process_Classes.ps1
----------------------------
using module 'D:\Exemple\Atelier\ClassImportProblem\ImportClasses.ps1'

$a = [ClassA]::new()
$b = [ClassB]::new()

class HustonweHaveAProblem
{
[void]HereWeGo(){
$a = [ClassA]::new()
$b = [ClassB]::new()
}
}

Observation:

From that point, instances of ClassA and ClassB are working fine in the process_Classes script. But instances of ClassA and ClassB within the class HustonWeHaveAProblem{} throw errors.

Actual result:

At D:\Exemple\Atelier\ClassImportProblem\process_Classes.ps1:9 char:15
+ $a = [ClassA]::new()
+ ~~~~~~
Unable to find type [ClassA].

At D:\Exemple\Atelier\ClassImportProblem\process_Classes.ps1:10 char:15
+ $b = [ClassB]::new()
+ ~~~~~~
Unable to find type [ClassB].
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : TypeNotFound

Expected Result:

Instances of classes should work within a class.

1 vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Gabriel Mailhot shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base