Description: There seems to be a problem when having base classes for DSC Resources you want to reuse. The problem occurs when having the 'Using module' clause, if you define the base class in the same file, no error is thrown. However, this way you cannot reuse base classes for multiple DSC Resources.
Full Example:
BaseDSC class is defined in a separate module 'Base'.
class BaseDSC {
[DscProperty(Key)]
[string] $Server
}
With 'Using module' I import it in the Resource module:
Using module Base
[DscResource()]
class DscResource : BaseDSC {
[DscProperty()]
[string] $Name
}
When you import the module and call Get-DscResource:
Import-Module -Name <Name of Module>
Get-DscResource
The following error is thrown:
Exception calling "ImportClassResourcesFromModule" with "3" argument(s): "Class feature already defined: Server
At line:9, char:23
Buffer:
[key]string Server;^
[r
"
At C:\windows\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2573 char:5
+ $resourcesFound = [Microsoft.PowerShell.DesiredStateConfiguration ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : CimException
The problem only occurs when calling Get-DscResource in the same process as Import-Module. If we Import the module in one process and call Get-DscResource in another, the error does not occur.
Description: There seems to be a problem when having base classes for DSC Resources you want to reuse. The problem occurs when having the 'Using module' clause, if you define the base class in the same file, no error is thrown. However, this way you cannot reuse base classes for multiple DSC Resources.
Full Example:
BaseDSC class is defined in a separate module 'Base'.
With 'Using module' I import it in the Resource module:
When you import the module and call Get-DscResource:
The following error is thrown:
The problem only occurs when calling Get-DscResource in the same process as Import-Module. If we Import the module in one process and call Get-DscResource in another, the error does not occur.