microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
23.37k stars 1.45k forks source link

winget configure fails with Could not load file or assembly 'Microsoft.WinGet.Client.Engine' #4160

Open JanDeDobbeleer opened 9 months ago

JanDeDobbeleer commented 9 months ago

Brief description of your issue

I'm trying to run a working configuration (provided by @denelon here) but it fails on my machine using the same configuration.

# yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  resources:
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: ohmyposh
      directives:
        description: Install Oh My Posh
        allowPrerelease: true
      settings:
        id: JanDeDobbeleer.OhMyPosh
        source: winget
  configurationVersion: 0.2.0

Steps to reproduce

Not sure, it seems to be device/environment specific.

Expected behavior

It succeeds in applying the configuration.

Actual behavior

It crashed with:

2024-02-11 16:11:28.178 [CORE] WinGet, version [1.7.3481-preview], activity [{E2EE6697-1F5F-4191-B391-FF74A7A0258C}]
2024-02-11 16:11:28.178 [CORE] OS: Windows.Desktop v10.0.22000.2538
2024-02-11 16:11:28.178 [CORE] Command line Args: "C:\Users\jan\AppData\Local\Microsoft\WindowsApps\winget.exe" configure C:\Users\jan\Documents\oh-my-posh.dsc.yaml --logs
2024-02-11 16:11:28.178 [CORE] Package: Microsoft.DesktopAppInstaller v1.22.3481.0
2024-02-11 16:11:28.178 [CORE] IsCOMCall:0; Caller: winget-cli
2024-02-11 16:11:28.181 [CLI ] WinGet invoked with arguments: 'configure' 'C:\Users\jan\Documents\oh-my-posh.dsc.yaml' '--logs'
2024-02-11 16:11:28.181 [CLI ] Found subcommand: configure
2024-02-11 16:11:28.181 [CLI ] Leaf command to execute: root:configure
2024-02-11 16:11:28.181 [CLI ] Executing command: configure
2024-02-11 16:11:33.915 [CONF] Configuration unit WinGetPackage[ohmyposh] failed with code 0x8a15c105 and error message:
Could not load file or assembly 'Microsoft.WinGet.Client.Engine, Version=1.21.0.0, Culture=neutral, PublicKeyToken=null'. Uncaught exception during type initialization. (0x80131534)
Microsoft.Management.Configuration.Processor.Exceptions.InvokeDscResourceException: Failed when calling `Test` for resource: WinGetPackage [Microsoft.WinGet.DSC] Message: 'Could not load file or assembly 'Microsoft.WinGet.Client.Engine, Version=1.21.0.0, Culture=neutral, PublicKeyToken=null'. Uncaught exception during type initialization. (0x80131534)
'
   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-02-11 16:11:33.915 [CLI ] Terminating context: 0x8a15c005 at C:\__w\1\s\external\pkg\src\AppInstallerCLICore\Workflows\ConfigurationFlow.cpp:3f9

Environment

Windows Package Manager (Preview) v1.7.3481-preview
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.22000.2538
System Architecture: Arm64
Package: Microsoft.DesktopAppInstaller v1.22.3481.0

Winget Directories                 
-----------------------------------------------------------------------------------------------------------------------
Logs                               %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\Diag…
User Settings                      %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\sett…
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
github-actions[bot] commented 9 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

denelon commented 9 months ago

@JanDeDobbeleer I'm asking the engineering team to take a look. I wasn't able to reproduce the error.

denelon commented 9 months ago

It would help to know which module version you have and the directory structure of the module, that dl must be under net6.0-windows10.0.22000\DirectDependencies.

JanDeDobbeleer commented 9 months ago

This is run with --verbose

2024-02-20 20:25:22.190 [CORE] WinGet, version [1.7.3481-preview], activity [{B42988C8-340C-4810-BAFB-6AC7BEFE0FB3}]
2024-02-20 20:25:22.190 [CORE] OS: Windows.Desktop v10.0.22000.2538
2024-02-20 20:25:22.190 [CORE] Command line Args: "C:\Users\jan\AppData\Local\Microsoft\WindowsApps\winget.exe" configure C:\Users\jan\AppData\Local\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\LocalState\oh-my-posh.configuration.yml --logs --verbose
2024-02-20 20:25:22.190 [CORE] Package: Microsoft.DesktopAppInstaller v1.22.3481.0
2024-02-20 20:25:22.190 [CORE] IsCOMCall:0; Caller: winget-cli
2024-02-20 20:25:22.196 [CLI ] WinGet invoked with arguments: 'configure' 'C:\Users\jan\AppData\Local\Packages\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\LocalState\oh-my-posh.configuration.yml' '--logs' '--verbose'
2024-02-20 20:25:22.196 [CLI ] Found subcommand: configure
2024-02-20 20:25:22.197 [CLI ] Leaf command to execute: root:configure
2024-02-20 20:25:22.197 [CLI ] Executing command: configure
2024-02-20 20:25:22.214 [CONF] Launching process for configuration processing...
2024-02-20 20:25:22.220 [CONF]   Configuration remote PID is 10084
2024-02-20 20:25:22.447 [CONF] ... configuration processing connection established.
2024-02-20 20:25:22.449 [CONF] Applying built in additional module path: C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.22.3481.0_arm64__8wekyb3d8bbwe\ExternalModules
2024-02-20 20:25:22.679 [CONF] [CONF] Parsing configuration set:
2024-02-20 20:25:22.679 [CONF] # yaml-language-server: $schema=https://aka.ms/configuration-dsc-schema/0.2
properties:
  resources:
    - resource: Microsoft.WinGet.DSC/WinGetPackage
      id: ohmyposh
      directives:
        description: Install Oh My Posh
        allowPrerelease: true
      settings:
        id: JanDeDobbeleer.OhMyPosh
        source: winget
  configurationVersion: 0.2.0

2024-02-20 20:25:22.679 [CONF] [YAML] Detected UTF-8
2024-02-20 20:25:22.961 [CONF] Creating set processor for `oh-my-posh.configuration.yml`...
2024-02-20 20:25:24.025 [CONF] Using winget module path
2024-02-20 20:25:24.025 [CONF]   Effective module path:
C:\Users\jan\AppData\Local\Microsoft\WinGet\Configuration\Modules;C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.22.3481.0_arm64__8wekyb3d8bbwe\ExternalModules;C:\Users\jan\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\windowsapps\microsoft.desktopappinstaller_1.22.3481.0_arm64__8wekyb3d8bbwe\configurationremotingserver\Modules;c:\program files (arm)\powershell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
2024-02-20 20:25:26.858 [CONF] PowerShellCommands: ['Import-Module' Parameters: FullyQualifiedName = '@{ ModuleName = 'PSDesiredStateConfiguration'; ModuleVersion = '2.0.7'; MaximumVersion = '2.999999999' }' ]

2024-02-20 20:25:26.858 [CONF] ... done creating set processor.
2024-02-20 20:25:26.880 [CONF] Getting unit details [ReadOnly] for: Microsoft.WinGet.DSC/WinGetPackage
2024-02-20 20:25:30.804 [CONF] Creating set processor for `oh-my-posh.configuration.yml`...
2024-02-20 20:25:30.861 [CONF] Using winget module path
2024-02-20 20:25:30.861 [CONF]   Effective module path:
C:\Users\jan\AppData\Local\Microsoft\WinGet\Configuration\Modules;C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.22.3481.0_arm64__8wekyb3d8bbwe\ExternalModules;C:\Users\jan\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;c:\program files\windowsapps\microsoft.desktopappinstaller_1.22.3481.0_arm64__8wekyb3d8bbwe\configurationremotingserver\Modules;c:\program files (arm)\powershell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules
2024-02-20 20:25:31.040 [CONF] ... done creating set processor.
2024-02-20 20:25:31.043 [CONF] Creating unit processor for: Microsoft.WinGet.DSC/WinGetPackage...
2024-02-20 20:25:31.359 [CONF] ... done creating unit processor.
2024-02-20 20:25:31.359 [CONF] Using unit from location: C:\Users\jan\AppData\Local\Microsoft\WinGet\Configuration\Modules\Microsoft.WinGet.DSC\0.2.0\Microsoft.WinGet.DSC.psd1
2024-02-20 20:25:31.362 [CONF] Invoking `Test` for resource: Microsoft.WinGet.DSC/WinGetPackage...
2024-02-20 20:25:31.654 [CONF] Microsoft.Management.Configuration.Processor.Exceptions.InvokeDscResourceException: Failed when calling `Test` for resource: WinGetPackage [Microsoft.WinGet.DSC] Message: 'Could not load file or assembly 'Microsoft.WinGet.Client.Engine, Version=1.21.0.0, Culture=neutral, PublicKeyToken=null'. Uncaught exception during type initialization. (0x80131534)
'
   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-02-20 20:25:31.654 [CONF] ... done invoking `Test`.
2024-02-20 20:25:31.678 [CONF] Configuration unit WinGetPackage[ohmyposh] failed with code 0x8a15c105 and error message:
Could not load file or assembly 'Microsoft.WinGet.Client.Engine, Version=1.21.0.0, Culture=neutral, PublicKeyToken=null'. Uncaught exception during type initialization. (0x80131534)
Microsoft.Management.Configuration.Processor.Exceptions.InvokeDscResourceException: Failed when calling `Test` for resource: WinGetPackage [Microsoft.WinGet.DSC] Message: 'Could not load file or assembly 'Microsoft.WinGet.Client.Engine, Version=1.21.0.0, Culture=neutral, PublicKeyToken=null'. Uncaught exception during type initialization. (0x80131534)
'
   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-02-20 20:25:31.679 [CLI ] Terminating context: 0x8a15c005 at C:\__w\1\s\external\pkg\src\AppInstallerCLICore\Workflows\ConfigurationFlow.cpp:3f9
JanDeDobbeleer commented 9 months ago

@denelon I had a look at the module paths and here are the versions which are present:

msftrubengu commented 9 months ago

1.21.2311.09003 is for the 1.6.3133.0 module version. I'm guessing if you run get-module microsoft.winget.client -ListAvailable in a pwsh session you will see two results (you need to add the local app data path to the psmodulepath tho)

Can you try loading the client module directly in pwsh from both locations? It might be easier to load the psd1 directly.

JanDeDobbeleer commented 9 months ago

@msftrubengu to be honest, I just want to be able to run winget configure and not deal with DLL hell. From a user POV, this should simply work: