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

error trying to install package provider (for powershell core) #477

Open
pwm1234 opened this issue Oct 23, 2019 · 38 comments
Open

error trying to install package provider (for powershell core) #477

pwm1234 opened this issue Oct 23, 2019 · 38 comments

Comments

@pwm1234
Copy link

pwm1234 commented Oct 23, 2019

I am having packaging problems with powershell core, so I submitted PowerShell/PowerShell#10867. But @iSazonov re-directed me to oneget. I am completely lost as to what is wrong, but I thought I would let you know. Perhaps the most fundamental problem is with get-packageprovider:

PS C:\Users\e27290> gcm get-packageprovider

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Cmdlet          Get-PackageProvider                                1.0.0.1    PackageManagement

But when I run it, I get this error:

PS C:\Users\e27290> get-packageprovider
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.PowerShel\u2026.GetPackageProvider:GetPackageProvider) [Get-PackageProvider], Exception
+ FullyQualifiedErrorId : UnhandledException,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider

This seems to be a powershell core problem not a oneget problem. (I do not have these problems with powershell.)

@SydneyhSmith
Copy link
Collaborator

@pwm1234 thanks for opening this issue, I noticed that your PackageManagement is not the latest version so this could be contributing to the issue, are you able to Update-Module PackageManagement

@pwm1234
Copy link
Author

pwm1234 commented Oct 25, 2019

No I get an error running update-module packagemanagement

PS > Update-Module PackageManagement                                                                     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:7365 char:25
+ ...     $null = PackageManagement\Import-PackageProvider -Name $script:Nu ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidData: (NuGet:String) [Import-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.ImportPackageProvider


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 (x86)\PackageManagement\ProviderAssemblies' or
'C:\Users\e27290\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.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.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](IDictionary`2 dictionary, TKey key, Func`1 valueFunction)
   at Microsoft.PackageManagement.Internal.Utility.Extensions.Singleton`1.GetOrAdd(Func`1 newInstance, Object primaryKey, Object[] keys)
   at Microsoft.PackageManagement.Internal.Utility.Extensions.SingletonExtensions.GetOrAdd[TResult](Object primaryKey, Func`1 newInstance, Object[] keys)
   at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders()
   at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters()
   at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>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.PowerShel\u2026tallPackageProvider:InstallPackageProvider) [Install-PackageProvider], Exception
+ FullyQualifiedErrorId : UnhandledException,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider

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.ImportPackageProvider

PackageManagement\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 name)
   at Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessProvidersFilteredByName()
   at Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessRecordAsync()
   at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>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.PowerShel\u2026.GetPackageProvider:GetPackageProvider) [Get-PackageProvider], Exception
+ FullyQualifiedErrorId : UnhandledException,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider

Update-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
+ Update-Module PackageManagement
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [Update-Module], InvalidOperationException
+ FullyQualifiedErrorId : CouldNotInstallNuGetProvider,Update-Module

@SydneyhSmith
Copy link
Collaborator

@pwm1234 thanks for trying that, we are planning to investigate this issue further, one potential workaround is by manually downloading the package provider, or if you have it saved on another machine copying over the dll

@pwm1234
Copy link
Author

pwm1234 commented Oct 31, 2019

Can you tell me how to manually download the package provider? Right now I am completely stuck and unable to do anything with powershell core 6 on my windows 10 laptop.

@electronic-dk
Copy link

electronic-dk commented Feb 1, 2020

I'm having a similar issue and I'm not sure if that's a powershell core issue or if I'm doing anything wrong. Trying to install (and even to simply find) ChocolateyGet provider fails in powershell core and succeeds in windows powershell:

Core:

VERBOSE: Using the provider 'Bootstrap' for searching packages.                                                                              VERBOSE: Finding the package 'Bootstrap::FindPackage' 'ChocolateyGet                                                                         VERBOSE: Using the provider 'PowerShellGet' for searching packages.                                                                        VERBOSE: The -Repository parameter was not specified.  PowerShellGet                                                                          will use all of the registered repositories.
VERBOSE: Getting the provider object for the PackageManagement Provi                                                                         der 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.co                                                                         m/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api                                                                         /v2/FindPackagesById()?id='ChocolateyGet'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'Chocolat                                                                         eyGet'.
Find-PackageProvider : No match was found for the specified search criteria and package name 'ChocolateyGet'. Try Get-PackageSource to see all available registered package sources.
At line:1 char:1
+ Find-PackageProvider ChocolateyGet -verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Microsoft.PowerShel\u2026FindPackageProvider:FindPackageProvider) [Find-PackageProvider], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackageProvider

vs

Windows PowerShell:

VERBOSE: Using the provider 'Bootstrap' for searching packages.
VERBOSE: Finding the package 'Bootstrap::FindPackage' 'ChocolateyGet','','','''.
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='ChocolateyGet'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'ChocolateyGet'.

Name                           Version          Source           Summary
----                           -------          ------           -------
ChocolateyGet                  1.0.0.1          PSGallery        An PowerShell OneGet provider that discovers packages from https://www.c...

Please, let me know if I can provider any additional info.

Powershell core version is 6.2.4, Windows 1909 18363.628

P.S. I'm just noticing a weird error output for powershell core:
ObjectNotFound: (Microsoft.PowerShel\u2026FindPackageProvider

I'm getting this both in Windows Terminal as well as in PowerShell's standalone window

@electronic-dk
Copy link

electronic-dk commented Feb 1, 2020

And just in general, windows powershell shows way more package providers when executing find-packageprovider than Core. Might it be that the package providers showing up in windows powershell and not in powershell core require full .NET and not .NET core?

@glatzert
Copy link

glatzert commented May 5, 2020

I've got a similar issue in #488 and it's just going in circles with no solution to be found.
Was someone in this issue able to resolve the problems, if something is misaligned on the machine or not correctly registered during install?
I'd like to move to PS Core, but I can't since neither my personal laptop nor my companies servers are able to use Find-Module at al, both with not having any PackageProviders and thus failing in circles.

@pwm1234
Copy link
Author

pwm1234 commented May 5, 2020

I have never resolved my original problems. I have given up on PS Core for the time being.

@iSazonov
Copy link

iSazonov commented May 5, 2020

You could try latest preview version.

@electronic-dk
Copy link

My guess is that many of the package providers target windows powershell and not powershell core, that's why they're not getting listed. Not sure how it can be solved, since most of those package providers offer windows-only packages and it doesn't make sense to port them over to other systems.

@alerickson
Copy link
Collaborator

What are the specific package providers you're trying to install @glatzert, @pwm1234 ?

@pwm1234
Copy link
Author

pwm1234 commented May 5, 2020

I will plead ignorance on this one. I was just trying to use powershell core across the board so that I did not use powershell on windows and bash on linux. I thought I would use powershell core everywhere. But when I did, I came across some package that needed to be installed (on windows) and simply executing this command get-packageprovider generated an error.

So I gave up on the pipedream of using powershell core as a multiplatform shell.

@alerickson
Copy link
Collaborator

@pwm1234 I was curious because for general package management (used in a generic sense) you can use PowerShellGet... we're working on a new version that will remove its dependency on PackageManagement to circumvent issues like this. However if you're trying to install another package provider that takes a dependency on PackageManagement, it might be a little trickier. It sounds like you probably fall into the former category? In which case you can try testing out the preview version of PowerShellGet v3. It still has limited capability but I'm working flushing it out and we should have a fully functioning preview in the next 2 months.

@pwm1234
Copy link
Author

pwm1234 commented May 5, 2020

Thank you for your help. I will admit to being a fairly dumb powershell user. I saw that powershell core was available on windows and linux, and I need a shell I can use on both. Plus, I (thought) I saw that powershell core was ready to replace powershell, so I thought I would try it first on windows. I guess all of this was a little premature. I do, however, look forward to using powershell core with full functionality on both windows and linux.

@thisjustin816
Copy link

I've been checking in on this issue for a while and finally have a workaround that worked on my machine. Just run this in Core:

Get-ChildItem -Path $env:PSModulePath.Split(';') -Filter 'PackageManagement' -Directory -ErrorAction SilentlyContinue |
    Get-ChildItem -Directory |
    Where-Object -Property Name -Match '\d*\.\d*\.\d*' |
    Get-ChildItem -Filter 'netstandard2.0' -Directory |
    ForEach-Object -Process {
        foreach ($clr in 'fullclr', 'coreclr') {
            Copy-Item -Path $_.FullName -Destination "$($_.Parent)\$clr" -Recurse -ErrorAction SilentlyContinue
        }
    }

@alerickson
Copy link
Collaborator

Thanks @thisjustin816 this gives me more insight into the original problem itself... I've never been able to repro this issue. Thanks for sharing your workaround.

@glatzert
Copy link

I found this: PowerShell/PowerShellGetv2#605

@alerickson
Copy link
Collaborator

As another workaround for this issue, if trying to install the NuGet package provider, you can retrieve the file this location: 'https://onegetcdn.azureedge.net/providers/Microsoft.PackageManagement.NuGetProvider-2.8.5.208.dll'

@ethanbergstrom
Copy link

This was a bug fixed in PowerShell 7.1. See PowerShell/PowerShell#12203

@4n-0n
Copy link

4n-0n commented Mar 21, 2022

PS Version: 7.2.2
Same problem.

@alerickson
Copy link
Collaborator

@mndhkr can you share the commands you're running and logs?

@chuckh1958
Copy link

Same problem in 7.2.3 too. I see it in both Windows powershell and powershell core.

I am trying to update DBATOOLS module and get this...

PS >update-module dbatools         
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.

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\chamilton\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

Install-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.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](IDictionary`2 dictionary, TKey key, Func`1      
valueFunction)    at Microsoft.PackageManagement.Internal.Utility.Extensions.Singleton`1.GetOrAdd(Func`1 newInstance, Object primaryKey, Object[]  
keys)    at Microsoft.PackageManagement.Internal.Utility.Extensions.SingletonExtensions.GetOrAdd[TResult](Object primaryKey, Func`1 newInstance,   
Object[] keys)    at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders()    at
Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters()    at
Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>b__0()'

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.

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 name)    at
Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessProvidersFilteredByName()    at
Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessRecordAsync()    at
Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>b__0()'

Update-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.

If I run Get-PackageProvider -ListAvailable though, I see that nuget is already installed...

PS >Get-PackageProvider -ListAvailable

Name                     Version          DynamicOptions
----                     -------          --------------
nuget                    2.8.5.208

@rad-ryanc
Copy link

Exactly as chuckh1958 posted above - This issue has been closed, but still appears to be an issue even now that we're on PS 7.2.4

@Chris-Irving
Copy link

Chris-Irving commented Jun 24, 2022

I've been checking in on this issue for a while and finally have a workaround that worked on my machine. Just run this in Core:

Get-ChildItem -Path $env:PSModulePath.Split(';') -Filter 'PackageManagement' -Directory -ErrorAction SilentlyContinue |
    Get-ChildItem -Directory |
    Where-Object -Property Name -Match '\d*\.\d*\.\d*' |
    Get-ChildItem -Filter 'netstandard2.0' -Directory |
    ForEach-Object -Process {
        foreach ($clr in 'fullclr', 'coreclr') {
            Copy-Item -Path $_.FullName -Destination "$($_.Parent)\$clr" -Recurse -ErrorAction SilentlyContinue
        }
    }

This lead me in the direction of fixing this problem for me in 7.2.5. $env:PSModulePath had "C:\Program Files\WindowsPowerShell\Modules" before "C:\Program Files\PowerShell\7\Modules". When I made the v7 path the first item I was able to install modules again.

Strangely, attempting to Update-Module PackageManagement reports an issue, but otherwise I experience no issues.

PS > Update-Module PackageManagement
Update-Module: Module 'PackageManagement' was not installed by using Install-Module, so it cannot be updated.

@chuckh1958
Copy link

chuckh1958 commented Jun 27, 2022 via email

@montella1507
Copy link

I have this problem in the latest Powershell Core hsoted in .NET Core application.

Nothing worked at all.... just turning in cykles.

@Zleep-Dogg
Copy link

I am also seeing this in powershell 7.3.4, although the error is a bit different.

This version of PowerShellGet requires minimum version '2.8.5.201' of NuGet provider to publish an
item to NuGet-based repositories. The NuGet provider must be available in 'C:\Program
Files\PackageManagement\ProviderAssemblies' or
'C:\Users\USERNAME\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"):
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(Stringinput)    at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.DefineDynamicType(Type
interfaceType)    at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType..ctor(Type
interfaceType, OrderedDictionary`2 methods, List`2 delegates, List`1 stubs)    at
Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.<>c__DisplayClass9_0.<Create>b__3()
at
Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary`2 dictionary, TKey key, Func`1 valueFunction)    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](Objectinstance)    at
Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost()    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](IDictionary`2 dictionary, TKey key, Func`1 valueFunction)    at
Microsoft.PackageManagement.Internal.Utility.Extensions.Singleton`1.GetOrAdd(Func`1 newInstance,
Object primaryKey, Object[] keys)    at
Microsoft.PackageManagement.Internal.Utility.Extensions.SingletonExtensions.GetOrAdd[TResult](ObjectprimaryKey, Func`1 newInstance, Object[] keys)    at
Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders()
at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters()
at
Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass85_0.<AsyncRun>b__0()'
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.
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(Stringinput)    at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.DefineDynamicType(Type
interfaceType)    at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType..ctor(Type
interfaceType, OrderedDictionary`2 methods, List`2 delegates, List`1 stubs)    at
Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.<>c__DisplayClass9_0.<Create>b__3()
at
Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary`2 dictionary, TKey key, Func`1 valueFunction)    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](Objectinstance)    at
Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost()    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__DisplayClass85_0.<AsyncRun>b__0()'
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.
Write-Error: Error initializing development environment

I tried installing the dll listed above in both the mentioned locations, but no success

If I run Get-PackageProvider -ListAvailable it comes up empty whereas windows powershell had some results

@Zleep-Dogg
Copy link

I just had an insight, after stumbling across PowerShellGetv2 #516, and sure enough, I can run stuff as windows admin!

without admin

>Get-PackageProvider -ListAvailable -Verbose -Debug
DEBUG: 00:00:00.0001911 Trying provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.ArchiverProviders.dll
DEBUG: 00:00:00.0005051 Trying provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.CoreProviders.dll
DEBUG: 00:00:00.0010853 Trying provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.NuGetProvider.dll
DEBUG: 00:00:00.0017596 Trying provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.MetaProvider.PowerShell.dll
DEBUG: 00:00:00.0087304 Attempting loading of assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.MetaProvider.PowerShell.dll
DEBUG: 00:00:00.0088692 Attempting loading of assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.ArchiverProviders.dll
DEBUG: 00:00:00.0089503 Attempting loading of assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.CoreProviders.dll
DEBUG: 00:00:00.0090218 Attempting loading of assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.NuGetProvider.dll
VERBOSE: Acquiring providers for assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.MetaProvider.PowerShell.dll
VERBOSE: Acquiring providers for assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.CoreProviders.dll
VERBOSE: Acquiring providers for assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.ArchiverProviders.dll
VERBOSE: Acquiring providers for assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.NuGetProvider.dll
DEBUG: 00:00:00.0388238 Registering providers via metaproviders for assembly Microsoft.PackageManagement.MetaProvider.PowerShell.Internal.PowerShellMetaProvider
DEBUG: 00:00:00.0730834 The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.
DEBUG: 00:00:00.0731359 The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.
DEBUG: 00:00:00.0732360 FAILED provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.NuGetProvider.dll
DEBUG: 00:00:00.0737141 One or more errors occurred. (The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.)
DEBUG: 00:00:00.0737145 One or more errors occurred. (The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.)
DEBUG: 00:00:00.0815676    at System.Threading.Tasks.Task.WaitAllCore(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
   at Microsoft.PackageManagement.Internal.Utility.Extensions.CollectionExtensions.WaitAll(IEnumerable`1 tasks)
   at Microsoft.PackageManagement.Internal.Implementation.PackageManagementService.AcquireProviders(String assemblyPath, IHostApi request, Boolean shouldRefreshCache)
DEBUG: 00:00:00.0815677    at System.Threading.Tasks.Task.WaitAllCore(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
   at Microsoft.PackageManagement.Internal.Utility.Extensions.CollectionExtensions.WaitAll(IEnumerable`1 tasks)
   at Microsoft.PackageManagement.Internal.Implementation.PackageManagementService.AcquireProviders(String assemblyPath, IHostApi request, Boolean shouldRefreshCache)
DEBUG: 00:00:00.0816814 FAILED provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.CoreProviders.dll
DEBUG: 00:00:00.0816820 FAILED provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.ArchiverProviders.dll
DEBUG: 00:00:00.1121943 One or more errors occurred. (The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Extensions.FilesystemExtensions' threw an exception.)
DEBUG: 00:00:00.1123451    at System.Threading.Tasks.Task.WaitAllCore(Task[] tasks, Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.WaitAll(Task[] tasks)
   at Microsoft.PackageManagement.Internal.Utility.Extensions.CollectionExtensions.WaitAll(IEnumerable`1 tasks)
   at Microsoft.PackageManagement.Internal.Implementation.PackageManagementService.AcquireProviders(String assemblyPath, IHostApi request, Boolean shouldRefreshCache)
DEBUG: 00:00:00.1124231 FAILED provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.MetaProvider.PowerShell.dll
VERBOSE: PowerShell meta provider initialization failed.

With PS elevated:

> get-PackageProvider -ListAvailable -Verbose -Debug
DEBUG: 00:00:00.0003083 Trying provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.CoreProviders.dll
DEBUG: 00:00:00.0002859 Trying provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.NuGetProvider.dll
DEBUG: 00:00:00.0002525 Trying provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.MetaProvider.PowerShell.dll
DEBUG: 00:00:00.0003027 Trying provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.ArchiverProviders.dll
DEBUG: 00:00:00.0079610 Attempting loading of assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.CoreProviders.dll
DEBUG: 00:00:00.0080881 Attempting loading of assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.ArchiverProviders.dll
DEBUG: 00:00:00.0081660 Attempting loading of assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.MetaProvider.PowerShell.dll
DEBUG: 00:00:00.0082368 Attempting loading of assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.NuGetProvider.dll
VERBOSE: Acquiring providers for assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.CoreProviders.dll
VERBOSE: Acquiring providers for assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.ArchiverProviders.dll
VERBOSE: Acquiring providers for assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.MetaProvider.PowerShell.dll
VERBOSE: Acquiring providers for assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.NuGetProvider.dll
DEBUG: 00:00:00.0463894 Registering providers via metaproviders for assembly Microsoft.PackageManagement.MetaProvider.PowerShell.Internal.PowerShellMetaProvider
DEBUG: 00:00:00.1338305 Initializing provider 'Bootstrap'
DEBUG: 00:00:00.1338858 Initializing provider 'zipfile'
DEBUG: 00:00:00.1339884 Initializing provider 'NuGet'
DEBUG: 00:00:00.1340379 Initializing provider 'WebDownloader'
DEBUG: 00:00:00.1582909 Provider 'zipfile' Initialized
DEBUG: 00:00:00.1584738 Provider 'WebDownloader' Initialized
DEBUG: 00:00:00.1585056 Using Archiver Provider zipfile
DEBUG: 00:00:00.1585599 Using Downloader Provider WebDownloader
DEBUG: 00:00:00.1588970 Initialize Bootstrapper
DEBUG: 00:00:00.1591669 Provider 'Bootstrap' Initialized
DEBUG: 00:00:00.1592710 Using Package Provider Bootstrap
DEBUG: 00:00:00.1813658 Calling 'NuGet'::'InitializeProvider'.
DEBUG: 00:00:00.1814836 Provider 'NuGet' Initialized
DEBUG: 00:00:00.1815038 Using Package Provider NuGet
DEBUG: 00:00:00.1829591 Calling 'WebDownloader::GetFeatures'
DEBUG: 00:00:00.1831250 Calling 'zipfile::GetFeatures'
DEBUG: 00:00:00.1832450 Calling 'Bootstrap::GetFeatures'
DEBUG: 00:00:00.1911202 The provider 'Bootstrap' is imported
DEBUG: 00:00:00.1915755 SUCCESS provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.ArchiverProviders.dll
DEBUG: 00:00:00.1916078 SUCCESS provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.CoreProviders.dll
DEBUG: 00:00:00.1919594 Calling 'NuGet'::'GetFeatures'.
DEBUG: 00:00:00.1934285 The provider 'NuGet' is imported
DEBUG: 00:00:00.1935379 SUCCESS provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.NuGetProvider.dll
DEBUG: 00:00:00.2400732 Trying to register metaprovider
DEBUG: 00:00:00.2434636 Initializing PowerShell MetaProvider
DEBUG: 00:00:00.6269854 Attempting to load PowerShell Provider Module [C:\dev\powershell\7\Modules\PowerShellGet\PSModule.psm1]
DEBUG: 00:00:01.7985100 Loaded PowerShell package provider: '[C:\dev\powershell\7\Modules\PowerShellGet\PSModule.psm1]'.
DEBUG: 00:00:01.8033006 Loaded PowerShell Provider: PowerShellGet
DEBUG: 00:00:01.8048830 Initializing provider 'PowerShellGet'
DEBUG: 00:00:01.8084289 Calling New() : MethodName = 'InitializeProvider'
DEBUG: 00:00:01.8085058 Verbose: True
DEBUG: 00:00:01.8085278 Debug: True
DEBUG: 00:00:01.8085421 ListAvailable: True
DEBUG: 00:00:01.8116670 INVOKING PowerShell Fn Initialize-Provider with args  that has length 0
DEBUG: 00:00:01.8188593 In PowerShellGet Provider - 'Initialize-Provider'.
DEBUG: 00:00:01.8191258 PowerShell Script 'PSModule' Function 'Initialize-Provider' returns null.
DEBUG: 00:00:01.8197991 Done calling powershell «Initialize-Provider» «PSModule»
DEBUG: 00:00:01.8198322 Provider 'PowerShellGet' Initialized
DEBUG: 00:00:01.8198458 Using Package Provider PowerShellGet
DEBUG: 00:00:01.8228452 Calling New() : MethodName = 'GetFeatures'
DEBUG: 00:00:01.8228787 Verbose: True
DEBUG: 00:00:01.8228944 Debug: True
DEBUG: 00:00:01.8229073 ListAvailable: True
DEBUG: 00:00:01.8234392 INVOKING PowerShell Fn Get-Feature with args  that has length 0
DEBUG: 00:00:01.8255928 In PowerShellGet Provider - 'Get-Feature'.
DEBUG: 00:00:01.8388388 Done calling powershell «Get-Feature» «PSModule»
DEBUG: 00:00:01.8389103 The provider 'PowerShellGet' is imported
DEBUG: 00:00:01.8401168 SUCCESS provider assembly: C:\dev\powershell\7\Modules\PackageManagement\coreclr\netstandard2.0\Microsoft.PackageManagement.MetaProvider.PowerShell.dll
DEBUG: 00:00:03.2530563 'PackageManagementProviders' key is not found in the .psd1 file under 'C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0'.
DEBUG: 00:00:03.2534078 'PackageManagementProviders' key is not found in the .psd1 file under 'C:\Program Files\WindowsPowerShell\Modules\PSReadline\2.0.0'.
DEBUG: 00:00:03.2534451 'PackageManagementProviders' key is not found in the .psd1 file under 'C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\LanguagePackManagement'.
DEBUG: 00:00:03.2546976 Attempting to load PowerShell Provider Module [C:\dev\powershell\7\Modules\PowerShellGet\PSModule.psm1]
DEBUG: 00:00:03.3607008 Loaded PowerShell package provider: '[C:\dev\powershell\7\Modules\PowerShellGet\PSModule.psm1]'.

Name                     Version          DynamicOptions
----                     -------          --------------
NuGet                    3.0.0.1          Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOn…
PowerShellGet            2.2.5.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherChec…
PowerShellGet            1.0.0.1

@montella1507
Copy link

@SydneyhSmith can we open this issue again? It is... blocking situation as far as it is core functionality

@SydneyhSmith
Copy link
Collaborator

Happy to re-open, it looks like it the past we fixed this is PowerShell and I don't expect a release of PackageManagement soon, so I need to do some debugging but may try to move it to another repo as well and make a bit of a fresh issue...trying to see if I can get a repro on it and do some debugging/read through old issues on this one

This was a bug fixed in PowerShell 7.1. See PowerShell/PowerShell#12203

@SydneyhSmith SydneyhSmith reopened this May 24, 2023
@montella1507
Copy link

I may be able to prepare for you small .NET Core (.NET 7) WinForms powered app with powershell (core) inside with 3 rows of Powershell. It is small part of bigger applications installing IIS, url rewrite etc on WinServer 2016/2019 so we need to get nuget provider there

@montella1507
Copy link

@SydneyhSmith just to be sure... are you interested?

@SydneyhSmith
Copy link
Collaborator

@montella1507 yep

@dayadam
Copy link

dayadam commented Jun 19, 2023

Also experiencing this @SydneyhSmith

@vandreytrindade
Copy link

Hi, I'm facing the same problem on PowerShell 7.3.6...
How can I fix this??? I'm not able to install anything!

@Alaknar
Copy link

Alaknar commented Dec 14, 2023

This seems to still be an issue on 7.4.0.

Install-Module -Name Microsoft.Graph.Users
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.

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\anza\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
Install-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.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](IDictionary`2
dictionary, TKey key, Func`1 valueFunction)    at
Microsoft.PackageManagement.Internal.Utility.Extensions.Singleton`1.GetOrAdd(Func`1 newInstance, Object primaryKey,
Object[] keys)    at
Microsoft.PackageManagement.Internal.Utility.Extensions.SingletonExtensions.GetOrAdd[TResult](Object primaryKey, Func`1
newInstance, Object[] keys)    at
Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders()    at
Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters()    at
Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>b__0()'
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.
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 name)    at
Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessProvidersFilteredByName()    at
Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessRecordAsync()    at
Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>b__0()'
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.

Get-PackageProvider
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()'

@jackvandeur
Copy link

Exactly as chuckh1958 posted above - This issue has been closed, but still appears to be an issue even now that we're on PS 7.2.4

Well I had the exact same problem and found that the correct path was missing to the powershell core modules folder. I added the path and shifted them in order as to first go to the core module path, then the users and lastly the v1.1 powershell modules folder. Rebooted the system and that worked for me.

@DavidGakwaya
Copy link

@jackvandeur Can you please share the details of your fix. Like your current core module path that works...

Mine is like this and isn't working.

C:\Users\user\Documents\PowerShell\Modules;C:\Program Files\PowerShell\Modules;%program files%\powershell\7\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules;C:\program files\powershell\7\Modules;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests