Skip to content

Type is not being imported script #11109

@chriskuech

Description

@chriskuech

I have a custom module that contains a class and some functions using that type. I am able to use this module without issue, except in one single script. All the script does is import the module with a relative path and invokes a function from that module, but the function throws the error below, somehow not having access to the type even though the type is confirmed to be imported into the session. When I import the module into my session prior to running the script, there is no issue. When I try and simplify my script and module into the minimal repro steps described below, I am unable to repro. If someone messages me on Teams, I can show you our repos so you can repro; otherwise, please let me know of any further debug steps I can try and take to further isolate this weird bug.

Steps to reproduce

Read the paragraph above!

  1. Create a module MyModule.
    1. Create a script MyModule.Types.ps1 containing--
      class MyType {}
    2. Create a file MyModule.psm1 containing--
      function Show-MyType {
          Param([MyType]$MyVal)
          Write-Host $MyVal
      }
    3. Set in the module manifest
      RootModule = 'MyModule.psm1'
      ScriptsToProcess = @( 'MyModule.Types.ps1' )
      FunctionsToExport = @( 'New-MyType' )
  2. Create a script
    $ModulePath = "relative path to the module"
    Import-Module $ModulePath
    
    $myVal = [MyType]::new()
    Show-MyType $myVal

Expected behavior

The script runs without error.

Actual behavior

Throws

Show-MyType : Unable to find type [Cluster].

Environment data


Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Microsoft Windows 10.0.18363 
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions