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
22.92k stars 1.42k forks source link

Winget PowerShell commands failing #3805

Closed RygelXVI closed 1 month ago

RygelXVI commented 10 months ago

Brief description of your issue

attempting to use any winget powershell commands will fail with "Get-WinGetPackage: Failed to create instance: -2147483633" using Get-WinGetPackage -Verbose -Debug does not produce further information. using try { get-wingetpackage } catch { $_.exception } captures the following stacktrace:

ErrorCode      : -2147483633
TargetSite     : T Create[T](System.Type, System.Guid ByRef)
Message        : Failed to create instance: -2147483633
Data           : {}
InnerException :
HelpLink       :
Source         : Microsoft.WinGet.Client.Engine
HResult        : -2147483633
StackTrace     :    at Microsoft.WinGet.Client.Engine.Helpers.ComObjectFactory.Create[T](Type type, Guid& iid)
                    at
                 Microsoft.WinGet.Client.Engine.Helpers.ComObjectFactory.CreateCreateCompositePackageCatalogOptions()
                    at Microsoft.WinGet.Client.Engine.Commands.Common.FinderCommand.GetPackageCatalogReference(Composit
                 eSearchBehavior behavior)
                    at Microsoft.WinGet.Client.Engine.Commands.Common.FinderCommand.GetPackageCatalog(CompositeSearchBe
                 havior behavior)
                    at
                 Microsoft.WinGet.Client.Engine.Commands.Common.FinderCommand.FindPackages(CompositeSearchBehavior
                 behavior, UInt32 limit)
                    at Microsoft.WinGet.Client.Engine.Commands.Common.FinderExtendedCommand.FindPackages(CompositeSearc
                 hBehavior behavior)
                    at Microsoft.WinGet.Client.Engine.Commands.FinderPackageCommand.Get()
                    at Microsoft.WinGet.Client.Commands.GetPackageCmdlet.ProcessRecord()
                    at System.Management.Automation.CommandProcessor.ProcessRecord()

Steps to reproduce

use a winget powershell command, e.g. get-wingetpackage | where { $_.Isupdateavailable }

Expected behavior

a list of packages with updates available to be displayed in the shell (in fact the same list of packages that would be displayed using winget upgrade

Actual behavior

error message "Get-WinGetPackage: Failed to create instance: -2147483633" is returned

Environment

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

Windows: Windows.Desktop v10.0.22621.2428
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.22.2782.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
Trenly commented 10 months ago

What version of PowerShell are you using?

RygelXVI commented 10 months ago

I'm using PowerShell 7.3.8, behaviour is also the same on 7.3.7

AmirTerani commented 10 months ago

Ran into a similar issue. Got the same "Failed to create instance: -2147483633" error with v0.2.2 but only when running Find-WingetPackage command in a script that was launched from an Scheduled Task with the Run whether user is logged on or not box checked on a Windows 10 workstation! Very unique! It worked properly in interactive sessions and in Windows 11. Downgrading the module to v0.2.1 didn't change anything, but then downgrading to v0.2.0 seems to have fixed the issue at first but it happened later on when I tried it again!

mdanish-kh commented 10 months ago

This looks like a problem with the MSIX-installed (user-scoped) version of PowerShell. Running it through the MSI-installed (machine-scoped) powershell works for me

https://github.com/microsoft/winget-cli/assets/88161975/12b77b8a-f3aa-4ff9-b342-84cf495e6bc1

cc @denelon

Note: If you want the MSI installer of PowerShell, you can get it using winget download Microsoft.PowerShell --installer-type wix

RygelXVI commented 10 months ago

on this (work) computer, PowerShell was installed from the Microsoft Store.
I don't see this problem on my personal computer, where PowerShell was installed with WinGet.

Can anyone clarify why there are issues between how PowerShell is installed? This seems very strange to me. Also why does using the -Verbose and -Debug switches not return any further information?

AmirTerani commented 10 months ago

I just uninstalled PS7 MSIX and manually downloaded and installed the MSI package. Still getting the same error when run the script from an Scheduled Task. Works fine in the console! Very odd!

eabase commented 10 months ago

Seem related to #3826

jaimecbernardo commented 8 months ago

In PowerToys, we're using https://www.powershellgallery.com/packages/Microsoft.WinGet.Client/1.6.3133.0 as a dependency on a new utility: Command Not Found. Unfortunately the plugin doesn't work on PowerShell when installed from the Microsoft Store or from .msix.

Ref: https://github.com/microsoft/PowerToys/issues/30818

Logue-0 commented 7 months ago

In PowerToys, we're using https://www.powershellgallery.com/packages/Microsoft.WinGet.Client/1.6.3133.0 as a dependency on a new utility: Command Not Found. Unfortunately the plugin doesn't work on PowerShell when installed from the Microsoft Store or from .msix.

Ref: microsoft/PowerToys#30818

Is there a third installation method that IS supported, then? I'm on Win11 and I'm trying to get it to work but I don't know how to update the bundled Powershell to version 7.**, just install the newer version as an MSIX

Neme12 commented 6 months ago

Damn, MSIX is still a second-class citizen, even today? :(

dongle-the-gadget commented 2 months ago

It seems like the MSIX version now works? Successful Get-WinGetPackage invocation with PSHOME indicating an MSIX installation of PowerShell

denelon commented 1 month ago

Can anyone confirm this has been fixed in the latest version of Microsoft.WinGet.Client? I believe this issue has been resolved.

jaimecbernardo commented 1 month ago

Hi @denelon , I can confirm the issue has been fixed for the use case in PowerToys when installing from the Microsoft Store. Thank you!

oldium commented 1 month ago

Works for me too. Thanks!

dongle-the-gadget commented 1 month ago

Should we closed this? Seems like it's fixed.