2

I've installed PowerShell 6.1.3 and I try to run some commands e.g.:

Get-PackageProvider

or

GetPackage

and then I get the following errors:

Get-PackageProvider : Unhandled Exception - Message:'The type initializer for
'Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType' threw an
exception.'
Name:'TypeInitializationException'
Stack Trace:'
   at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.Create(Type tInterface, OrderedDictionary`2 instanceMethods, List`2 delegateMethods, List`1 stubMethods, List`2 usedInstances)
   at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface, Object[] instances)
   at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(Type tInterface, Object[] instances)
   at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast[TInterface](Object[] instances)
   at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterfaceExtensions.As[TInterface](Object instance)
   at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost()
   at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String[] names)
   at Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessRecordAsync()
   at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>b__0()'
At line:1 char:1
+ Get-PackageProvider
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (Microsoft.Power...PackageProvider:GetPackageProvider) [Get-PackageProvider], Exception
+ FullyQualifiedErrorId : UnhandledException,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider

How can I resolve this issue?

Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
agawa17
  • 315
  • 1
  • 3
  • 10

1 Answers1

0

I also faced the similar issue, running the Nuget related commands threw the exception. But, then I ran the similar commands in "Powershell in Admin mode" and I could resolve the problem.

  • https://meta.stackoverflow.com/a/285557/11107541 – starball May 04 '23 at 09:28
  • Please add code and data as text ([using code formatting](//stackoverflow.com/editing-help#code)), not images. Images: A) don't allow us to copy-&-paste the code/errors/data for testing; B) don't permit searching based on the code/error/data contents; and [many more reasons](//meta.stackoverflow.com/a/285557). Images should only be used, in addition to text in code format, if having the image adds something significant that is not conveyed by just the text code/error/data. – Adrian Mole May 04 '23 at 11:52