Skip to content

System.IO.Pipelines missing from the TRUSTED_PLATFORM_ASSEMBLIES array #114

Description

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.

Steps to reproduce

When running some PowerShell command that needs System.IO.Pipelines remotely (so via wsmprovhost.exe), it fails with a FileNotFoundException, because the file could not be located & loaded into the default ALC (Assembly Load Context). Of course, this could happen with other modules as well.

The file does exist & is in the right place, correct version.

The problem seems to be that the ALC is initialized with string.Empty for basePaths (raised a separate issue item for that -> PowerShell/PowerShell#27982 also specifically System.IO.Pipelines is missing from TRUSTED_PLATFORM_ASSEMBLIES list, which is what I'm opening this issue for.

e.g:

PS C:\> Invoke-Command -ComputerName  srv-2025.skynet.lab -ConfigurationName powershell.7 -ScriptBlock {
     
     # We need to run something to trigger the loading of System.IO.Pipelines. Interacting with a repository using v3 APIs will trigger it while parsing the JSON (e.g: nuget.org).
     Find-PSResource -Name Newtonsoft.Json -Repository NuGet -Verbose
}

Find-PSResource: Could not load file or assembly 'System.IO.Pipelines, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Run this locally & remotely to confirm:

[pscustomobject]@{
    ProcessPath = [Environment]::ProcessPath
    BaseDirectory = [AppContext]::BaseDirectory
    DepsFiles = [AppContext]::GetData('APP_CONTEXT_DEPS_FILES')
    HasPipelinesInTPA = (
        [AppContext]::GetData('TRUSTED_PLATFORM_ASSEMBLIES') -split ';'
    ).Where({ [IO.Path]::GetFileName($_) -eq 'System.IO.Pipelines.dll' }).Count -gt 0
}

LOCAL:

ProcessPath : C:\Program Files\PowerShell\7\pwsh.exe 
BaseDirectory : C:\Program Files\PowerShell\7\
DepsFile : C:\Program Files\PowerShell\7\pwsh.deps.json   
HasPipelinesInTPA : True

REMOTE:

ProcessPath : C:\Windows\system32\wsmprovhost.exe
BaseDirectory :
DepsFiles :
HasPipelinesInTPA : False
PSComputerName : srv-2025.skynet.lab

This is the flow that leads to the problem:
-> PSResourceGet V3ServerAPICalls
-> System.Text.Json loaded to parse .json response
-> PooledByteBufferWriter from System.Text.Json has a dependency (extends) on PipeWriter, which is coming from System.IO.Pipelines
-> bind System.IO.Pipelines v10.0.0.0 — token cc7b13ffcd2ddd51
-> not in ALC already
-> empty basePaths / __probingPaths
-> not in TRUSTED_PLATFORM_ASSEMBLIES
-> fallback as last resort to legacy GAC / MSIL (not found there either, but not expected to be there anyway)
-> FileNotFoundException

If you manually import the module in the ALC, before running the command, it all works fine.
e.g:

Invoke-Command -ComputerName srv-2025.skynet.lab -ConfigurationName powershell.7 -ScriptBlock {
 
     [System.Runtime.Loader.AssemblyLoadContext]::Default.LoadFromAssemblyPath((Join-Path $PSHOME 'System.IO.Pipelines.dll'))

      # We need to run something to trigger the loading of System.IO.Pipelines. Interacting with a repository using v3 APIs will trigger it while parsing the JSON (e.g: nuget.org).
      Find-PSResource -Name Newtonsoft.Json -Repository NuGetV3Lab
}


GAC    Version        Location                                         PSComputerName
---    -------        --------                                         --------------
False  v4.0.30319     C:\Program Files\PowerShell\7\System.IO.Pipelin… srv-2025.skynet.lab

Author                   : James Newton-King
...
Name                     : Newtonsoft.Json
ProjectUri               : https://www.newtonsoft.com/json
...

Of course, if basePaths (aka ALC.__probingPaths) wouldn't be empty, then it would also work fine. But for that, I raised the other issue.

2068206b0e8(System.Management.Automation.PowerShellAssemblyLoadContext)._probingPaths
[raw] 00000206820239d8 System.String[] Length: 0

Expected behavior

The ALC loads System.IO.Pipelines & the command runs successfully.

Actual behavior

Find-PSResource: Could not load file or assembly 'System.IO.Pipelines, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Error details

OriginInfo            :  srv-2025.skynet.lab
Exception             :
    Type                           : System.Management.Automation.RemoteException
    SerializedRemoteException      : System.IO.FileNotFoundException: Could not load file or assembly
'System.IO.Pipelines, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the
file specified.
                                     File name: 'System.IO.Pipelines, Version=10.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'
                                     at System.Text.Json.JsonDocument.Dispose()
                                     at
Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls.GetJsonElementArr(String request, String propertyName,
Int32& totalHits, ErrorRecord& errRecord) in C:\__w\1\s\PSResourceGet\src\code\V3ServerAPICalls.cs:line 1528
                                     at
Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls.GetJsonElementArr(String request, String propertyName,
Int32& totalHits, ErrorRecord& errRecord) in C:\__w\1\s\PSResourceGet\src\code\V3ServerAPICalls.cs:line 1498
    SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
    ErrorRecord                    :
        Exception             :
            Type                           : System.Management.Automation.RemoteException
            SerializedRemoteException      : System.IO.FileNotFoundException: Could not load file or assembly
'System.IO.Pipelines, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the
file specified.
                                             File name: 'System.IO.Pipelines, Version=10.0.0.0, Culture=neutral,
PublicKeyToken=cc7b13ffcd2ddd51'
                                             at System.Text.Json.JsonDocument.Dispose()
                                             at
Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls.GetJsonElementArr(String request, String propertyName,
Int32& totalHits, ErrorRecord& errRecord) in C:\__w\1\s\PSResourceGet\src\code\V3ServerAPICalls.cs:line 1528
                                             at
Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls.GetJsonElementArr(String request, String propertyName,
Int32& totalHits, ErrorRecord& errRecord) in C:\__w\1\s\PSResourceGet\src\code\V3ServerAPICalls.cs:line 1498
            SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
            ErrorRecord                    :
                Exception             :
                    Type                           : System.Management.Automation.RemoteException
                    SerializedRemoteException      : System.IO.FileNotFoundException: Could not load file or assembly
'System.IO.Pipelines, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the
file specified.
                                                     File name: 'System.IO.Pipelines, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
                                                     at System.Text.Json.JsonDocument.Dispose()
                                                     at
Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls.GetJsonElementArr(String request, String propertyName,
Int32& totalHits, ErrorRecord& errRecord) in C:\__w\1\s\PSResourceGet\src\code\V3ServerAPICalls.cs:line 1528
                                                     at
Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls.GetJsonElementArr(String request, String propertyName,
Int32& totalHits, ErrorRecord& errRecord) in C:\__w\1\s\PSResourceGet\src\code\V3ServerAPICalls.cs:line 1498
                    SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
                    ErrorRecord                    :
                        Exception             :
                            Type                           : System.Management.Automation.RemoteException
                            SerializedRemoteException      : System.IO.FileNotFoundException: Could not load file or
assembly 'System.IO.Pipelines, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot
find the file specified.
                                                             File name: 'System.IO.Pipelines, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
                                                             at System.Text.Json.JsonDocument.Dispose()
                                                             at
Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls.GetJsonElementArr(String request, String propertyName,
Int32& totalHits, ErrorRecord& errRecord) in C:\__w\1\s\PSResourceGet\src\code\V3ServerAPICalls.cs:line 1528
                                                             at
Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls.GetJsonElementArr(String request, String propertyName,
Int32& totalHits, ErrorRecord& errRecord) in C:\__w\1\s\PSResourceGet\src\code\V3ServerAPICalls.cs:line 1498
                            SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
                            ErrorRecord                    :
                                Exception             :
                                    Type                           : System.Management.Automation.RemoteException
                                    SerializedRemoteException      : System.IO.FileNotFoundException: Could not load
file or assembly 'System.IO.Pipelines, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system
cannot find the file specified.
                                                                     File name: 'System.IO.Pipelines,
Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
                                                                     at System.Text.Json.JsonDocument.Dispose()
                                                                     at
Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls.GetJsonElementArr(String request, String propertyName,
Int32& totalHits, ErrorRecord& errRecord) in C:\__w\1\s\PSResourceGet\src\code\V3ServerAPICalls.cs:line 1528
                                                                     at
Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls.GetJsonElementArr(String request, String propertyName,
Int32& totalHits, ErrorRecord& errRecord) in C:\__w\1\s\PSResourceGet\src\code\V3ServerAPICalls.cs:line 1498
                                    SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
                                    ErrorRecord                    : …
                                    Message                        : Could not load file or assembly
'System.IO.Pipelines, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the
file specified.
                                    HResult                        : -2146233087
                                TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls
                                CategoryInfo          : InvalidResult:
(Microsoft.PowerShel…ts.V3ServerAPICalls:V3ServerAPICalls) [Find-PSResource], FileNotFoundException
                                FullyQualifiedErrorId :
GetResponsesFromRegistrationsResourceFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource
                                ScriptStackTrace      : at <ScriptBlock>, <No file>: line 32
                            Message                        : Could not load file or assembly 'System.IO.Pipelines,
Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
                            HResult                        : -2146233087
                        TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls
                        CategoryInfo          : InvalidResult:
(Microsoft.PowerShel…ts.V3ServerAPICalls:V3ServerAPICalls) [Find-PSResource], FileNotFoundException
                        FullyQualifiedErrorId :
GetResponsesFromRegistrationsResourceFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource
                        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 32
                    Message                        : Could not load file or assembly 'System.IO.Pipelines,
Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
                    HResult                        : -2146233087
                TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls
                CategoryInfo          : InvalidResult: (Microsoft.PowerShel…ts.V3ServerAPICalls:V3ServerAPICalls)
[Find-PSResource], FileNotFoundException
                FullyQualifiedErrorId :
GetResponsesFromRegistrationsResourceFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource
                ScriptStackTrace      : at <ScriptBlock>, <No file>: line 32
            Message                        : Could not load file or assembly 'System.IO.Pipelines, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
            HResult                        : -2146233087
        TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls
        CategoryInfo          : InvalidResult: (Microsoft.PowerShel…ts.V3ServerAPICalls:V3ServerAPICalls)
[Find-PSResource], FileNotFoundException
        FullyQualifiedErrorId :
GetResponsesFromRegistrationsResourceFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 32
    Message                        : Could not load file or assembly 'System.IO.Pipelines, Version=10.0.0.0,
Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
    HResult                        : -2146233087
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.V3ServerAPICalls
CategoryInfo          : InvalidResult: (Microsoft.PowerShel…ts.V3ServerAPICalls:V3ServerAPICalls) [Find-PSResource],
FileNotFoundException
FullyQualifiedErrorId :
GetResponsesFromRegistrationsResourceFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.FindPSResource
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 32

Environment data

$PSVersionTable inserted in the ScriptBlock. I cannot test with PowerShell 7.7 preview, because it does not come with a pwrshplugin.dll & PSSessionConfiguration.

Nevertheless, the problematic code is present in the latest master branch.

Name                           Value
----                           -----
Platform                       Win32NT
PSRemotingProtocolVersion
PSEdition                      Core
OS                             Microsoft Windows 10.0.26100
PSVersion                      7.6.5
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
GitCommitId                    7.6.5
WSManStackVersion              3.0
SerializationVersion           1.1.0.1

Version

7.6.5

Visuals

Fail:
Image

Works (if "preloading" in the ALC):
Image

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions