Skip to content

If a module 'test' has multiple nested .psm1 modules that define powershell classes, then using module test can only load the classes defined in test.psm1 but not other .psm1 files #4114

Closed

Description

Steps to reproduce

Module structure:

PS:81> tree.com F:\tmp\test /F
F:\TMP\TEST
    class.psm1
    test.psd1
    test.psm1

Content of class.psm1

class Foo
{
    [string] $Name = "Foo"
}

Content of test.psm1

using module .\class.psm1

class Bar{
    [Foo] $foo = [Foo]::new()

    [void] Print()
    {
        Write-Host ($this.foo.Name)
    }
}

Content of test.psd1

@{
ModuleVersion = '1.0'
GUID = 'e812e452-6a43-4fe7-9738-375c2fbdd577'
NestedModules = @("class.psm1", "test.psm1")
FunctionsToExport = @()
CmdletsToExport = @()
VariablesToExport = '*'
AliasesToExport = @()
}

Content of run.ps1

using module F:\tmp\test
[Bar]
[Foo]

Run run.ps1

Expected behavior

Both `[Bar]` and `[Foo]` should be resolved.

Actual behavior

PS:90> .\run.ps1
Unable to find type [Foo].
At F:\tmp\test\class.psm1:1 char:1
+ class Foo
+ ~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (class Foo
{
 ...Name = "Foo"
}:TypeDefinitionAst) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
GitCommitId                    v6.0.0-beta.2-48-g598cebf7b2f0b5bb0b0add97c6393ccfaaa792f5-dirty
OS                             Microsoft Windows 10.0.15063
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    WG-Engine
    Issue-Bug
    on Jun 28, 2017
  2. jasonshave commented on Aug 9, 2018

    @jasonshave

    is there a workaround at the moment?

  3. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  4. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  5. added
    Resolution-No Activity
    on Nov 16, 2023
  6. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  7. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugResolution-No ActivityWG-Engine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions