PowerShell / PowerShell/DSC

Class-based resource leveraging types from another module failure

Open
#854 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Bug Need-Review
Dominant language
Rust
Stars
523
Forks
75
Avg merge
3d 16h
Merged PRs (30d)
24

Description

Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.
Summary

I have a class-based DSC resource module AnyPackageDsc that leverages types from AnyPackage. In the DSC module it has a using module AnyPackage. Intermittently it will fail throwing an error saying types were not found. If you try again the issue goes away.

Related issue: https://github.com/PowerShell/PSDesiredStateConfiguration/issues/104

Steps to reproduce
  1. Create a DSC class-based resource module that requires types from another module
  2. Execute dsc --trace-level trace resource list --adapter Microsoft.Dsc/PowerShell
Expected behavior
Should not error
Actual behavior
2025-05-29T20:52:22.161678Z  INFO dsc_lib::discovery::command_discovery: 359: Enumerating resources for adapter 'Microsoft.DSC/PowerShell'
2025-05-29T20:52:22.163337Z DEBUG dsc_lib::dscresources::command_resource: 699: Invoking command 'pwsh' with args Some(["-NoLogo", "-NonInteractive", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", "./psDscAdapter/powershell.resource.ps1 List"])
2025-05-29T20:52:22.600328Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 31836: PSVersion=7.5.1
2025-05-29T20:52:22.601088Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 31836: PSPath=C:\Program Files\PowerShell\7
2025-05-29T20:52:22.601625Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 31836: PSModulePath=C:\Users\tnieto\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\powershell\7\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
2025-05-29T20:52:22.603919Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 31836: jsonInput=@{}
2025-05-29T20:52:22.728971Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 31836: Reading from Get-DscResource cache file C:\Users\tnieto\AppData\Local\dsc\PSAdapterCache.json
2025-05-29T20:52:22.736147Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 31836: Checking cache for stale entries
2025-05-29T20:52:22.755562Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 31836: Detected stale cache entry 'C:\Users\tnieto\Documents\PowerShell\Modules\TestClassResource\0.0.1\nested.psm1'
2025-05-29T20:52:22.757467Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 31836: Constructing Get-DscResource cache
2025-05-29T20:52:24.723012Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Found 2 modules with name 'AnyPackageDsc'
2025-05-29T20:52:24.730962Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from module 'C:\Users\tnieto\Documents\PowerShell\Modules\AnyPackageDsc\0.2.0\AnyPackageDsc.psd1'
2025-05-29T20:52:24.736977Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from file 'C:\Users\tnieto\Documents\PowerShell\Modules\AnyPackageDsc\0.2.0\AnyPackageDsc.psm1'
2025-05-29T20:52:24.812876Z ERROR dsc_lib::dscresources::command_resource: 896: PID 31836:
Extent                   ErrorId      Message                                         IncompleteInput
------                   -------      -------                                         ---------------
PackageNotFoundException TypeNotFound Unable to find type [PackageNotFoundException].           False


2025-05-29T20:52:24.813846Z ERROR dsc_lib::dscresources::command_resource: 896: PID 31836:
Extent         ErrorId      Message                               IncompleteInput
------         -------      -------                               ---------------
PackageVersion TypeNotFound Unable to find type [PackageVersion].           False


2025-05-29T20:52:24.814365Z ERROR dsc_lib::dscresources::command_resource: 896: PID 31836:
Extent                    ErrorId      Message                                          IncompleteInput
------                    -------      -------                                          ---------------
PackageProviderOperations TypeNotFound Unable to find type [PackageProviderOperations].           False


2025-05-29T20:52:24.815047Z ERROR dsc_lib::dscresources::command_resource: 896: PID 31836:
Extent                         ErrorId      Message                                               IncompleteInput
------                         -------      -------                                               ---------------
PackageSourceNotFoundException TypeNotFound Unable to find type [PackageSourceNotFoundException].           False


2025-05-29T20:52:24.850349Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from module 'C:\Users\tnieto\Documents\PowerShell\Modules\Microsoft.WinGet.DSC\1.10.340\Microsoft.WinGet.DSC.psd1'
2025-05-29T20:52:24.851057Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from file 'C:\Users\tnieto\Documents\PowerShell\Modules\Microsoft.WinGet.DSC\1.10.340\Microsoft.WinGet.DSC.psm1'
2025-05-29T20:52:24.856642Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from module 'C:\Users\tnieto\Documents\PowerShell\Modules\Test\Test.psd1'
2025-05-29T20:52:24.857424Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from file 'C:\Users\tnieto\Documents\PowerShell\Modules\Test\Test.psm1'
2025-05-29T20:52:24.868933Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from module 'C:\Users\tnieto\Documents\PowerShell\Modules\TestClassResource\0.0.1\TestClassResource.psd1'
2025-05-29T20:52:24.869507Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from file 'C:\Users\tnieto\Documents\PowerShell\Modules\TestClassResource\0.0.1\TestClassResource.psm1'
2025-05-29T20:52:24.879387Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from module 'C:\Users\tnieto\Documents\PowerShell\Modules\XmlContentDsc\0.0.1\XmlContentDsc.psd1'
2025-05-29T20:52:24.880628Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from file 'C:\Users\tnieto\Documents\PowerShell\Modules\XmlContentDsc\0.0.1\XmlContentDsc.psm1'
2025-05-29T20:52:24.882026Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from module 'C:\Users\tnieto\Documents\PowerShell\Modules\XmlDsc\XmlDsc.psd1'
2025-05-29T20:52:24.883455Z TRACE dsc_lib::dscresources::command_resource: 904: PID 31836: Loading resources from file 'C:\Users\tnieto\Documents\PowerShell\Modules\XmlDsc\XmlDsc.psm1'
2025-05-29T20:52:25.042690Z DEBUG dsc_lib::dscresources::command_resource: 902: PID 31836: Saving Get-DscResource cache to 'C:\Users\tnieto\AppData\Local\dsc\PSAdapterCache.json'
2025-05-29T20:52:25.910334Z DEBUG dsc_lib::dscresources::command_resource: 660: Process 'pwsh' id 31836 exited with code 0
2025-05-29T20:52:25.913848Z DEBUG dsc_lib::discovery::command_discovery: 413: Adapter 'Microsoft.DSC/PowerShell' listed 12 resources
2025-05-29T20:52:25.915495Z DEBUG dsc_lib::discovery::command_discovery: 803: Read 956 items into lookup table from "C:\\Users\\tnieto\\AppData\\Local\\dsc\\AdaptedResourcesLookupTable.json"

Type                                       Kind      Version   Capabilities  RequireAdapter            Description
------------------------------------------------------------------------------------------------------------------------
AnyPackageDsc/Package                      Resource  0.2.0     gs--t---      Microsoft.DSC/PowerShell  AnyPackage DSC r…
AnyPackageDsc/Source                       Resource  0.2.0     gs--t---      Microsoft.DSC/PowerShell  AnyPackage DSC r…
Microsoft.WinGet.DSC/WinGetAdminSettings   Resource  1.10.340  gs--t---      Microsoft.DSC/PowerShell  PowerShell Modul…
Microsoft.WinGet.DSC/WinGetPackage         Resource  1.10.340  gs--t---      Microsoft.DSC/PowerShell  PowerShell Modul…
Microsoft.WinGet.DSC/WinGetPackageManager  Resource  1.10.340  gs--t---      Microsoft.DSC/PowerShell  PowerShell Modul…
Microsoft.WinGet.DSC/WinGetSource          Resource  1.10.340  gs--t---      Microsoft.DSC/PowerShell  PowerShell Modul…
Microsoft.WinGet.DSC/WinGetUserSettings    Resource  1.10.340  gs--t---      Microsoft.DSC/PowerShell  PowerShell Modul…
Test/Abc                                   Resource  0.0.1     gs--t---      Microsoft.DSC/PowerShell
TestClassResource/NoExport                 Resource  0.0.1     g-----e-      Microsoft.DSC/PowerShell
TestClassResource/TestClassResource        Resource  0.0.1     g-----e-      Microsoft.DSC/PowerShell
XmlContentDsc/XmlFileContentResource       Resource  0.0.1     gs--t---      Microsoft.DSC/PowerShell  Module with DSC …
XmlDsc/XmlElementValue                     Resource  0.0.1     gs--t---      Microsoft.DSC/PowerShell
Error details
2025-05-29T20:52:24.812876Z ERROR dsc_lib::dscresources::command_resource: 896: PID 31836:
Extent                   ErrorId      Message                                         IncompleteInput
------                   -------      -------                                         ---------------
PackageNotFoundException TypeNotFound Unable to find type [PackageNotFoundException].           False


2025-05-29T20:52:24.813846Z ERROR dsc_lib::dscresources::command_resource: 896: PID 31836:
Extent         ErrorId      Message                               IncompleteInput
------         -------      -------                               ---------------
PackageVersion TypeNotFound Unable to find type [PackageVersion].           False


2025-05-29T20:52:24.814365Z ERROR dsc_lib::dscresources::command_resource: 896: PID 31836:
Extent                    ErrorId      Message                                          IncompleteInput
------                    -------      -------                                          ---------------
PackageProviderOperations TypeNotFound Unable to find type [PackageProviderOperations].           False


2025-05-29T20:52:24.815047Z ERROR dsc_lib::dscresources::command_resource: 896: PID 31836:
Extent                         ErrorId      Message                                               IncompleteInput
------                         -------      -------                                               ---------------
PackageSourceNotFoundException TypeNotFound Unable to find type [PackageSourceNotFoundException].           False
Environment data
7.6-preview4
Version

3.1-preview6

Visuals

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the dsc --trace-level trace resource list --adapter Microsoft.Dsc/PowerShell reproduction and inspect the psDscAdapter/powershell.resource.ps1 entry point named in the trace. Compare successful and failing discovery runs, focusing on loading AnyPackageDsc and its using module AnyPackage types; done means repeated resource listing completes without TypeNotFound errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell, rust
Domain
backend, cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.