Install-Module Microsoft.WinGet.Client fails with TypeInitializationException in FilesystemExtensions due to stale PackageManagement temp folder permissions

未关闭
#6,605 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
powershell
领域
cli

调研方向

Start by reproducing the failure with Install-Module -Name Microsoft.WinGet.Client and inspect the reported PackageManagement FilesystemExtensions.MakeSafeFileName initialization error. The issue names no repository files or tests, so locate the relevant implementation and tests from that entry point; done means the NuGet provider bootstrap succeeds despite the stale temp folder permissions.

由索引模型根据 Issue 内容生成。

描述

Command-Install Issue-Bug
Relevant area(s)

WinGet CLI

Relevant command(s)

winget install

Brief description of your issue

Attempting to install the Microsoft.WinGet.Client PowerShell module fails during the NuGet provider bootstrap sequence. Instead of prompting for the provider installation, the PackageManagement engine throws an unhandled TypeInitializationException for Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions. This renders Install-Module, Install-PackageProvider, and Get-PackageProvider unusable in the current session, preventing the WinGet client module from being installed.

Steps to reproduce

Open Windows PowerShell (or PowerShell) as a standard user or administrator.

Run Install-Module -Name Microsoft.WinGet.Client.

When prompted to install the NuGet provider, respond Y (Yes).

Expected behavior

The NuGet provider (version 2.8.5.201 or newer) should install successfully, followed by the installation of the Microsoft.WinGet.Client module from the PowerShell Gallery.

Actual behavior

The provider bootstrap fails immediately with a TypeInitializationException. The full error trace shows the failure originates in FilesystemExtensions.MakeSafeFileName, cascading through the plugin initialization logic of PackageManagement.

PackageManagement\Install-PackageProvider : Unhandled Exception - Message:'The type initializer for
'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.'
Name:'TypeInitializationException' Stack Trace:' at
Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions.MakeSafeFileName(String input)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.DefineDynamicType(Type interfaceType)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType..ctor(Type interfaceType, OrderedDictionary2 methods, List2 delegates, List`1 stubs)
...
at Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider.get_SelectedProviders()

PS C:\WINDOWS\system32> Install-Module -Name Microsoft.WinGet.Client

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The
NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\Taylo\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by
running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"):
PS C:\WINDOWS\system32> Install-Module -Name Microsoft.WinGet.Client

NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The
NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\Taylo\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by
running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install
and import the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y
PackageManagement\Install-PackageProvider : Unhandled Exception - Message:'The type initializer for
'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.'
Name:'TypeInitializationException' Stack Trace:' at
Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions.MakeSafeFileName(String input)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.DefineDynamicType(Type interfaceType)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType..ctor(Type interfaceType, OrderedDictionary2 methods, List2 delegates, List1 stubs) at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.<>c__DisplayClass9_0.<Create>b__3() at Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary2
dictionary, TKey key, Func1 valueFunction) at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.Create(Type tInterface, OrderedDictionary2
instanceMethods, List2 delegateMethods, List1 stubMethods, List2 usedInstances) at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface, Object[] instances) at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast[TInterface](Object[] instances) at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String[] names) at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_SelectedProviders() at Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider.get_SelectedProviders() at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.<get_CachedSelectedProviders>b__23_0() at Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary2
dictionary, TKey key, Func`1 valueFunction)
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders()
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters()
at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.b__0()'
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7468 char:21

  • ... $null = PackageManagement\Install-PackageProvider -Name $script:N ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (Microsoft.Power...PackageProvider:InstallPackageProvider) [Install-
      PackageProvider], Exception
    • FullyQualifiedErrorId : UnhandledException,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvid
      er

PackageManagement\Import-PackageProvider : No match was found for the specified search criteria and provider name
'NuGet'. Try 'Get-PackageProvider -ListAvailable' to see if the provider exists on the system.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7474 char:21

  • ... $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (NuGet:String) [Import-PackageProvider], Exception
    • FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackagePr
      ovider

PackageManagement\Get-PackageProvider : Unhandled Exception - Message:'The type initializer for
'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.'
Name:'TypeInitializationException' Stack Trace:' at
Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions.MakeSafeFileName(String input)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.DefineDynamicType(Type interfaceType)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType..ctor(Type interfaceType, OrderedDictionary2 methods, List2 delegates, List1 stubs) at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.<>c__DisplayClass9_0.<Create>b__3() at Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary2
dictionary, TKey key, Func1 valueFunction) at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.Create(Type tInterface, OrderedDictionary2
instanceMethods, List2 delegateMethods, List1 stubMethods, List`2 usedInstances)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface, Object[]
instances)
at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast[TInterface](Object[]
instances)
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String name)
at Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessProvidersFilteredByName()
at Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessRecordAsync()
at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.b__0()'
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:7478 char:30

  • ... tProvider = PackageManagement\Get-PackageProvider -Name $script:NuGet ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageP
      rovider], Exception
    • FullyQualifiedErrorId : UnhandledException,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider

Install-Module : NuGet provider is required to interact with NuGet-based repositories. Please ensure that
'2.8.5.201' or newer version of NuGet provider is installed.
At line:1 char:1

  • Install-Module -Name Microsoft.WinGet.Client
  •   + CategoryInfo          : InvalidOperation: (:) [Install-Module], InvalidOperationException
      + FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Install-Module
    
    

PS C:\WINDOWS\system32>

After this failure, subsequent commands confirm the provider is missing
Install-Module : NuGet provider is required to interact with NuGet-based repositories. Please ensure that
'2.8.5.201' or newer version of NuGet provider is installed.

Environment
[winget --info]
Windows Package Manager version: [Run `winget --info` and paste output here]
Windows: Windows.Desktop version [e.g., 10.0.19045.0]
Package: Microsoft.DesktopAppInstaller version [e.g., 1.22.x]

PowerShell Version: 5.1 (Windows PowerShell) / PowerShell 7.x
OS Architecture: x64
主要语言
C++
星标
26.6k
派生
1.8k
平均合并
3 天 10 小时
30 天内合并 PR
41

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/winget-cli 的其他 Issue

查看 microsoft/winget-cli 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。