-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Description
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!
- Create a module
MyModule.- Create a script
MyModule.Types.ps1containing--class MyType {}
- Create a file
MyModule.psm1containing--function Show-MyType { Param([MyType]$MyVal) Write-Host $MyVal }
- Set in the module manifest
RootModule = 'MyModule.psm1' ScriptsToProcess = @( 'MyModule.Types.ps1' ) FunctionsToExport = @( 'New-MyType' )
- Create a script
- 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