Prerequisites
Version
v2.0
Links
-
-
-
|
> [!NOTE] |
|
> The class defined for the **Reasons** property is named `MyModuleReason` instead of `Reason`, |
|
> using the module's name as a prefix. While you can give the class any name, if two or more |
|
> modules define a class with the same name and are both used in a configuration, PowerShell raises |
|
> an exception. |
|
> |
|
> To avoid exceptions caused by name conflicts in DSC and machine configuration, always prefix the |
|
> name of the class you define for the **Reasons** property. |
-
Summary
If a class or enum is defined with the same name in more than one module, compiling configurations that use both of those modules fails due to the name collision.
Details
We already partially cover this problem for defining the Reasons property for machine configuration:
|
> [!NOTE] |
|
> The class defined for the **Reasons** property is named `MyModuleReason` instead of `Reason`, |
|
> using the module's name as a prefix. While you can give the class any name, if two or more |
|
> modules define a class with the same name and are both used in a configuration, PowerShell raises |
|
> an exception. |
|
> |
|
> To avoid exceptions caused by name conflicts in DSC and machine configuration, always prefix the |
|
> name of the class you define for the **Reasons** property. |
We should generalize this note and advice and surface it wherever it makes sense.
Suggested Fix
We should document this behavior, suggest that authors prefix their enums and classes with their module name, and add name prefixing to the best practices section for the Class-based DSC Resources article.
We may want to add an include that we can use throughout the documentation wherever we're talking about naming classes and enums for use as DSC Resource property types.
Prerequisites
Get-Foocmdlet" instead of "Typo."Version
v2.0
Links
PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Line 258 in 9a81631
PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Line 309 in 9a81631
PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Line 365 in 9a81631
PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Lines 559 to 566 in 9a81631
PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Line 794 in 9a81631
Summary
If a class or enum is defined with the same name in more than one module, compiling configurations that use both of those modules fails due to the name collision.
Details
We already partially cover this problem for defining the Reasons property for machine configuration:
PowerShell-Docs-DSC/dsc/docs-conceptual/dsc-2.0/concepts/class-based-resources.md
Lines 559 to 566 in 9a81631
We should generalize this note and advice and surface it wherever it makes sense.
Suggested Fix
We should document this behavior, suggest that authors prefix their enums and classes with their module name, and add name prefixing to the best practices section for the Class-based DSC Resources article.
We may want to add an include that we can use throughout the documentation wherever we're talking about naming classes and enums for use as DSC Resource property types.