Skip to content

Reloading module does not reload submodules. #2505

@powercode

Description

@powercode

Steps to reproduce

#Sub.psm1:
  class Sub {
    [int] $Value
  }

#modrepo.psm1:
  using module .\Sub.psm1

  function Get-Sub { 
     [Sub]@{
         Value = 42
     }
  }

Import-Module modrepo
Get-Sub

Value : 1

Change the definition of Sub:

#Sub.psm1:
  class Sub {  
    [string] $Name # added field
    [int] $Value
  }

#modrepo.psm1:
  using module .\Sub.psm1

  function Get-Sub{ 
     [Sub]@{
         Name = Staffan # added field
         Value = 42
     }
  }

#Then

Remove-Module -force modrepo
Import-Module -force modrepo
Get-Sub 

Expected behavior

output of object of class Sub with

Name : 'Staffan'
Value : 42

Actual behavior

Cannot create object of type "Sub". The Name property was not found for the Sub object. The available property is: [Value <System.Int32>]
At C:\Users\<user>\Documents\WindowsPowerShell\Modules\modrepo\modrepo.psm1:9 char:3
+   [Sub] @{
+   ~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [], RuntimeException
    + FullyQualifiedErrorId : ObjectCreationError

Environment data

Name                           Value                                                                                                                                                       
----                           -----                                                                                                                                                       
PSVersion                      5.1.14393.206                                                                                                                                               
PSEdition                      Desktop                                                                                                                                                     
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                     
BuildVersion                   10.0.14393.206                                                                                                                                              
CLRVersion                     4.0.30319.42000                                                                                                                                             
WSManStackVersion              3.0                                                                                                                                                         
PSRemotingProtocolVersion      2.3                                                                                                                                                         
SerializationVersion           1.1.0.1                                                                                                                                                     


Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productKeepOpenThe bot will ignore these and not auto-closeWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions