Skip to content

Latest commit

 

History

History

Cannot-derive-from-dot-sourced

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Cannot derive from dot sourced

PowerShell classes can be defined by commands like scripts, functions, script blocks and imported to the current scope using dot-sourcing.

Such dot-sourced classes can be used for basic operations like instantiation and invocation of members. See the script Test-1.can.use.ps1.

It is not possible though to define a new class derived from a dot-sourced class. See the script Test-2.cannot.derive.ps1.

See also Parser-fails-on-custom-type. The issue is similar. A possible workaround is to move the definition of derived classes to a script and dot-source it after dot-sourcing base classes.

Another workaround is suggested in PowerShellTraps/issues/10. Define or get the derived class source as a string and use Invoke-Expression. See Test-3.workaround.ps1.