Repository navigation
Closed
Labels
Issue-Code Cleanupthe issue is for cleaning up the code with no impact on functionalityResolution-FixedThe issue is fixed.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Description
I have a module that loads a nested binary module (due to support for desktop and core editions). The binary module defines a provider that has a default PSDrive.
When calling Get-ChieldItem <qualified path> it fails with "Cannot find a provider with the name '...'". This has changed since 6.0 when it used to work.
I have created a sample repro module:
Summary:
- The module must be nested to get this to reproduce
- The provider must do something at initialization time that triggers a capture of the Provider.FullName (or something like that). In my case this is the PSDriveInfo constructor probably:
protected override Collection<PSDriveInfo> InitializeDefaultDrives() {
var drive = new PSDriveInfo(
"defaultSampleDrive",
ProviderInfo,
"/",
"Sample default drive",
null);
var result = new Collection<PSDriveInfo> {drive};
return result;
}If the InitializeDefaultDrives in the sample is removed, then the issue would not be reproduced.
Steps to reproduce
- Build the sample module with
dotnet build - Load the module from the build output and run the following:
import-module "...ReproModule.psd1"
New-PSDrive -Name "prv1" -Root "/" -PSProvider "SamplePrv"
$item = get-item "prv1:\test.txt"
$item | fl *
Get-ChildItem $item.PSPath- Observe the PSPath value
Expected behavior
The command to return the item like this:
PSPath PSProvider PSIsContainer Name
------ ---------- ------------- ----
ReproModule\SamplePrv::test.txt ReproModule\SamplePrv False test.txt
Probably the PSPath value should be:
PSPath : ReproModule\SamplePrv::test.txt
Actual behavior
PSPath value is:
PSPath : module\SamplePrv::test.txt
The command fails with:
Get-ChildItem : Cannot find a provider with the name 'module\SamplePrv'.
At line:1 char:1
+ Get-ChildItem $item.PSPath
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (module\SamplePrv:String) [Get-ChildItem], ProviderNotFoundException
+ FullyQualifiedErrorId : ProviderNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
Environment data
Name Value
---- -----
PSVersion 6.2.1
PSEdition Core
GitCommitId 6.2.1
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Metadata
Metadata
Assignees
Labels
Issue-Code Cleanupthe issue is for cleaning up the code with no impact on functionalityResolution-FixedThe issue is fixed.WG-Engine-Providersbuilt-in PowerShell providers such as FileSystem, Certificates, Registry, etc.
Activity
atanasa commentedon Jun 6, 2019
This is probably also affecting other provider-related cmdlets. We are seeing that when calling
New-PSDrive -Name someName -Root 'drive:/...' -PSProvider ...the call to the provider implementation (PSDriveInfo NewDrive(PSDriveInfo requestedDrive)) receives the root in the form of a PSPath instead of the root in the provider path which was the case before. Looking at the code ofGetProviderRootFromSpecifiedRoot, it looks like the provider full name might be involved in the resolution of the PSPath to the provider path.Is there some way to enable the tracing that is present in the path resolution code?
iSazonov commentedon Jun 13, 2019
See LocationGlobber and PathResolution from Get-TraceSource
atanasa commentedon Oct 3, 2019
This is not a question but a report of an issue. The issue has not been solved, please reopen the issue.
iSazonov commentedon Oct 3, 2019
Can you repo with latest 7.0 build?
atanasa commentedon Oct 4, 2019
It still reproduces with preview 4:
iSazonov commentedon Jan 31, 2020
Atanas Atanasov (@atanasa) I compiled your sample module and do not see the issue with latest PowerShell 7.0 build..
atanasa commentedon Jan 31, 2020
I am able to reproduce it with rc2. I am testing on Windows 10.
The error output is:
Get-ChildItem: Cannot find a provider with the name 'module\SamplePrv'.Stack trace:
The
$PSTableVersion:This is the compiled version of the module:
ReproModule.zip
iSazonov commentedon Jan 31, 2020
Atanas Atanasov (@atanasa) Thanks! I can repo. It comes from SnapIn history. The name
module\SamplePrvlooks like SnapIn name and not all code was leaned up from SnapIn support.Error starts here:
PowerShell/src/System.Management.Automation/engine/SessionStateProviderAPIs.cs
Line 786 in c4e144b
and
PowerShell/src/System.Management.Automation/engine/MshSnapinQualifiedName.cs
Lines 65 to 81 in c4e144b
The GetInstance() method has 11 references so it's very risky to change.
Atanas Atanasov (@atanasa) I suggest to find a workaround and/or redesign your module. Perhaps Patrick Meinecke (@SeeminglyScience) know a workaround.
Steve Lee (@SteveL-MSFT) I think the old SnapIn code could be removed in next milestone. It seems it currently is a source of tricky issues for users and developers.
SeeminglyScience commentedon Jan 31, 2020
Ilya (@iSazonov) the class is named snapin, but it's just provider code. Also this is actually a side effect of #8831. Since the full name is cached now, creating those drives on initialization locks in the name at the wrong time.
You can verify this by clearing the cached field via reflection:
iSazonov commentedon Jan 31, 2020
The ProviderInfo class is immutable. It makes me think that a root reason of the issue is still different.
atanasa commentedon Feb 3, 2020
I agree with Patrick Meinecke (@SeeminglyScience). The "immutability" does not contradict that explanation. The issue is triggered by the early initialization of
ProviderInfo.FullNamethat calls intoModuleInfo.Name.ModuleInfo.Nameis not immutable and its name is updated at a later point for some reason. AsProviderInfo.FullNameis immutable, it is not update to reflect the new name of the module.SeeminglyScience commentedon Feb 3, 2020
Ilya (@iSazonov) does have a point, it's puzzling. So I took a deeper look.
First, this actually has a much simpler repro and isn't related to nested modules at all. All you need is a
RootModuledll with a file name different from the name declared in the module manifest.The problem is that provider drive initialization happens before the module is renamed to match the manifest here:
PowerShell/src/System.Management.Automation/engine/Modules/ModuleCmdletBase.cs
Lines 3085 to 3086 in a34d0f3
The caching is still why it happens, but not in the way I expected.
iSazonov commentedon Feb 3, 2020
I pulled direct fix. It is not nice but the code is tricky too :-)
Patrick Meinecke (@SeeminglyScience) Thanks for pointing where nested module name updated.