Skip to content
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

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

Open
Skyb0rg007 opened this issue Dec 15, 2024 · 5 comments
Labels
Command-Configure Issue related to WinGet Configuration DSC-Resource Issue related to DSC Resources Issue-Bug It either shouldn't be doing this or needs an investigation.

Comments

@Skyb0rg007
Copy link

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
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage Issue need to be triaged label Dec 15, 2024
@cypherfunc
Copy link

My team is having the same problem; we use winget configs to set up new PCs. The person I'm setting up today is getting Microsoft.WinGet.DSC v1.10.90 and getting this error, but the person I helped two weeks ago has Microsoft.WinGet.DSC v1.9.25190 and it worked fine. This is definitely a bug in v1.10.90, or due to a related change.

@mdanish-kh
Copy link
Contributor

Looks related to microsoft/winget-dsc#140 (comment). Quoting the remediation from @JohnMcPMS in that issue:

One thing that definitely does work is to remove the allowPrerelease from all of the configuration units in the file. You may also have to clear %LOCALAPPDATA%\Microsoft\WinGet\Configuration\Modules to ensure that the preview module isn't present.

In the meantime, the mitigations are:

  1. Avoid using the prerelease module as suggested above.
  2. Use the Microsoft.WinGet.Configuration preview module (which I would expect has similar issues due to that dll)

@microsoft-github-policy-service microsoft-github-policy-service bot added Command-Configure Issue related to WinGet Configuration Issue-Bug It either shouldn't be doing this or needs an investigation. DSC-Resource Issue related to DSC Resources and removed Needs-Triage Issue need to be triaged labels Dec 16, 2024
@Skyb0rg007
Copy link
Author

Thanks, at least for the time being uninstalling the module and removing allowPrerelease: true works for me.

@cypherfunc
Copy link

Yup! That fix worked for us too. Thanks @mdanish-kh !

@denelon
Copy link
Contributor

denelon commented Dec 17, 2024

@cypherfunc I'd love to get some additional information on how you're using WinGet Configuration to set new machines up. If you're up for it, please send me an e-mail to discuss.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Command-Configure Issue related to WinGet Configuration DSC-Resource Issue related to DSC Resources Issue-Bug It either shouldn't be doing this or needs an investigation.
Projects
None yet
Development

No branches or pull requests

4 participants