microsoft / microsoft/winget-cli

`Microsoft.WinGet.DSC/WinGetPackage`: The type initializer for '<Module>' threw an exception.

Open
#5,069 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Command-Configure DSC-Resource Issue-Bug
Dominant language
C++
Stars
26.4k
Forks
1.8k
Avg merge
1d 11h
Merged PRs (30d)
15

Description

Brief description of your issue

The DSC module that comes with the winget cli is throwing an exception when run from winget configure.
This prevents the installation of winget packages through the DSC module.

Steps to reproduce

Create a configuration.dsc.yaml file:

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  resources:
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      directives:
        description: Install Zotero
        allowPrerelease: true
      settings:
        Id: DigitalScholar.Zotero
        Source: winget
  configurationVersion: 0.2.0

Run winget

> winget configure test .\configuration.dsc.yaml
Apply :: WinGetPackage
  Install Zotero
  Module: Microsoft.WinGet.DSC by Microsoft Corporation [Local]
    https://github.com/microsoft/winget-cli
    PowerShell Module with DSC resources related to WinGet configurations
  Settings:
    Id: DigitalScholar.Zotero
    Source: winget
You are responsible for understanding the configuration settings you are choosing to execute. Microsoft is not responsible for the configuration file you have authored or imported. This configuration may change settings in Windows, install software, change software settings (including security settings), and accept user agreements to third-party packages and services on your behalf.  By running this configuration file, you acknowledge that you understand and agree to these resources and settings. Any applications installed are licensed to you by their owners. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages or services.
Have you reviewed the configuration and would you like to proceed verifying it against the system?
[Y] Yes  [N] No: y
Apply :: WinGetPackage
  The configuration unit failed while attempting to test the current system state.
The type initializer for '<Module>' threw an exception.
<See the log file for additional details>
Some of the configuration units failed while testing their state.
Expected behavior
> winget configure test .\configuration.dsc.yaml
Apply :: WinGetPackage
  Install Zotero
  Module: Microsoft.WinGet.DSC by Microsoft Corporation [Local]
    https://github.com/microsoft/winget-cli
    PowerShell Module with DSC resources related to WinGet configurations
  Settings:
    Id: DigitalScholar.Zotero
    Source: winget
You are responsible for understanding the configuration settings you are choosing to execute. Microsoft is not responsible for the configuration file you have authored or imported. This configuration may change settings in Windows, install software, change software settings (including security settings), and accept user agreements to third-party packages and services on your behalf.  By running this configuration file, you acknowledge that you understand and agree to these resources and settings. Any applications installed are licensed to you by their owners. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages or services.
Have you reviewed the configuration and would you like to proceed verifying it against the system?
[Y] Yes  [N] No: y
Apply :: WinGetPackage
  System is in the described configuration state.
System is in the described configuration state.

(Or "not in the described configuration state", depending)

Actual behavior

The command throws an exception during "type initialization", and does not test for the presence of the package.
By manually modifying the .psm1 file, the Test() method of the WinGetPackage is not entered; the error occurs before then.

The log file includes:

2024-12-15 01:40:43.871 [CORE] WinGet, version [1.10.40-preview], activity [{FFD88D23-CD50-4AE2-B000-46D93134B81C}]
2024-12-15 01:40:43.871 [CORE] OS: Windows.Desktop v10.0.26100.1742
2024-12-15 01:40:43.871 [CORE] Command line Args: "C:\Users\skyle\AppData\Local\Microsoft\WindowsApps\winget.exe" configure test .\configurations\apps.dsc.yaml
2024-12-15 01:40:43.871 [CORE] Package: Microsoft.DesktopAppInstaller v1.25.40.0
2024-12-15 01:40:43.871 [CORE] IsCOMCall:0; Caller: winget-cli
2024-12-15 01:40:43.880 [CLI ] WinGet invoked with arguments: 'configure' 'test' '.\configurations\apps.dsc.yaml'
2024-12-15 01:40:43.880 [CLI ] Found subcommand: configure
2024-12-15 01:40:43.880 [CLI ] Found subcommand: test
2024-12-15 01:40:43.880 [CLI ] Leaf command to execute: root:configure:test
2024-12-15 01:40:43.883 [CLI ] Executing command: test
2024-12-15 01:40:43.885 [FAIL] WindowsPackageManager.dll!00007FFF69AEBBF4: LogHr(1) tid(3fb0) 80070057 The parameter is incorrect.

2024-12-15 01:40:44.649 [CONF] The set processor factory is running in limit mode: False.
2024-12-15 01:40:48.490 [CONF] GetUnitProcessorDetails is running in limit mode: False.
2024-12-15 01:40:51.869 [CONF] The set processor factory is running in limit mode: False.
2024-12-15 01:40:52.241 [CONF] [CONF] Testing configuration unit: `` [WinGetPackage]
2024-12-15 01:40:52.242 [CONF] GetUnitProcessorDetails is running in limit mode: False.
2024-12-15 01:40:53.001 [CONF] Configuration unit WinGetPackage[] failed with code 0x8a15c105 and error message:
The type initializer for '<Module>' threw an exception.
Microsoft.Management.Configuration.Processor.Exceptions.InvokeDscResourceException: Failed when calling `Test` for resource: WinGetPackage [Microsoft.WinGet.DSC] Message: 'The type initializer for '<Module>' threw an exception.
'
   at Microsoft.Management.Configuration.Processor.DscModule.DscModuleV2.InvokeTestResource(PowerShell pwsh, ValueSet settings, String name, ModuleSpecification moduleSpecification)
   at Microsoft.Management.Configuration.Processor.Runspaces.HostedEnvironment.InvokeTestResource(ValueSet settings, String name, ModuleSpecification moduleSpecification)
   at Microsoft.Management.Configuration.Processor.Unit.ConfigurationUnitProcessor.TestSettings()
2024-12-15 01:40:53.108 [CLI ] Terminating context: 0x8a15c00f at C:\__w\1\s\external\pkg\src\AppInstallerCLICore\Workflows\ConfigurationFlow.cpp:5f6
Environment
Windows Package Manager (Preview) v1.10.40-preview
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.26100.1742
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.25.40.0

Winget Directories
-------------------------------------------------------------------------------------------------------------------------------
Logs                               %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\DiagOutputDir
User Settings                      %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json
Portable Links Directory (User)    %LOCALAPPDATA%\Microsoft\WinGet\Links
Portable Links Directory (Machine) C:\Program Files\WinGet\Links
Portable Package Root (User)       %LOCALAPPDATA%\Microsoft\WinGet\Packages
Portable Package Root              C:\Program Files\WinGet\Packages
Portable Package Root (x86)        C:\Program Files (x86)\WinGet\Packages
Installer Downloads                %USERPROFILE%\Downloads

Links
---------------------------------------------------------------------------
Privacy Statement   https://aka.ms/winget-privacy
License Agreement   https://aka.ms/winget-license
Third Party Notices https://aka.ms/winget-3rdPartyNotice
Homepage            https://aka.ms/winget
Windows Store Terms https://www.microsoft.com/en-us/storedocs/terms-of-sale

Admin Setting                             State
--------------------------------------------------
LocalManifestFiles                        Disabled
BypassCertificatePinningForMicrosoftStore Disabled
InstallerHashOverride                     Disabled
LocalArchiveMalwareScanOverride           Disabled
ProxyCommandLineOptions                   Disabled
DefaultProxy                              Disabled

OS: Windows 11 (Pro) x86_64
Host: XPS 13 9310
Shell: PowerShell 7.4.6
Terminal: Windows Terminal 1.21.3231.0

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

Reproduce the failure with configuration.dsc.yaml and inspect the winget configuration logs around WinGetPackage and DscModule.InvokeTestResource. Compare the failing Test invocation with the expected successful state check; done means winget configure test completes without the type-initializer exception and reports the package state.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.