Skip to content

fix: Check Type instance has DscResource attribute #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

haodeon
Copy link

@haodeon haodeon commented May 14, 2025

PR Summary

PR #797 introduced a workaround to detect if DSC resources were ClassBased. This PR adds an additional validation by checking the instance has the DscResource attribute.

PR Context

The workaround incorrectly sets ImplementationDetail to ClassBased when there is another type with the same name, like TimeZone or Environment.

@Gijsreyn
Copy link
Contributor

Nice catch @haodeon!

Comment on lines 228 to 229
if ($classBased -and ($instance.GetProperties() | Where-Object {
$_.CustomAttributes.AttributeType.Name -eq 'DscPropertyAttribute' } | Select-Object -First 1)) {
"Detected class-based resource: $($dscResource.Name) => Type: $($classBased.BaseType.FullName)" | Write-DscTrace
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking the properties, you can check whether the class has the [DscResource()] attribute - any class with that attribute is checked for validity as a PSDSC resource at parse time - those checks (that you have the correct method signatures, at least one key property, etc) are built directly into the parser.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code now checks for DscResource attribute instead of scanning properties for DscProperty attribute.

@haodeon haodeon force-pushed the fix/winPS-ClassBased branch from 00d97b2 to e7e6292 Compare May 15, 2025 03:47
@haodeon haodeon changed the title fix: Check instance properties have DscProperty attribute fix: Check Type instance has DscResource attribute May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants