Skip to content

PowerShell installed as global tool with .NET 6 fails to run on Alpine 3.15 #16532

Closed

Description

Prerequisites

Steps to reproduce

I've installed PowerShell as a global tool with .NET 6 in an Alpine 3.15 container. When attempting to run pwsh, it results in the following error:

PowerShell 7.2.0
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

One or more errors occurred. (The type initializer for 'System.Management.Automation.TypeAccelerators' threw an exception.)
One or more errors occurred. (The type initializer for 'System.Management.Automation.TypeAccelerators' threw an exception.)
Cannot load PSReadline module.  Console is running without PSReadline.
Process terminated. The type initializer for 'System.Management.Automation.PSObject' threw an exception.
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
   at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSObject' threw an exception.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   --- End of inner exception stack trace ---
   at System.Management.Automation.PSObject.get_Properties()
   at System.Management.Automation.HostUtilities.GetDollarProfile(String allUsersAllHosts, String allUsersCurrentHost, String currentUserAllHosts, String currentUserCurrentHost)
   at Microsoft.PowerShell.ConsoleHost.DoRunspaceInitialization(Boolean skipProfiles, String initialCommand, String configurationName, Collection`1 initialCommandArgs)
   at Microsoft.PowerShell.ConsoleHost.DoCreateRunspace(String initialCommand, Boolean skipProfiles, Boolean staMode, String configurationName, Collection`1 initialCommandArgs)
   at Microsoft.PowerShell.ConsoleHost.CreateRunspace(Object runspaceCreationArgs)
   at Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(String initialCommand, Boolean skipProfiles, Collection`1 initialCommandArgs, Boolean staMode, String configurationName)
   at Microsoft.PowerShell.ConsoleHost.Run(CommandLineParameterParser cpp, Boolean isPrestartWarned)
   at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)

Repro Steps:

  1. Build the following Dockerfile (e.g. docker build -t test .):
FROM alpine:3.15

RUN apk add --no-cache \
        ca-certificates \
        \
        # .NET dependencies
        icu-libs \
        krb5-libs \
        libgcc \
        libintl \
        libssl1.1 \
        libstdc++ \
        zlib

# Install .NET SDK
RUN wget -O dotnet.tar.gz https://dotnetcli.blob.core.windows.net/dotnet/Sdk/6.0.100/dotnet-sdk-6.0.100-linux-musl-x64.tar.gz \
    && mkdir -p /usr/share/dotnet \
    && tar -C /usr/share/dotnet -oxzf dotnet.tar.gz \
    && ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet

# Install PowerShell
RUN dotnet tool install --global PowerShell

ENTRYPOINT [ "/root/.dotnet/tools/pwsh" ]
  1. Run the container (e.g. docker run --rm test)

Expected behavior

A successful execution into the shell of PowerShell

Actual behavior

One or more errors occurred. (The type initializer for 'System.Management.Automation.TypeAccelerators' threw an exception.)
One or more errors occurred. (The type initializer for 'System.Management.Automation.TypeAccelerators' threw an exception.)
Cannot load PSReadline module.  Console is running without PSReadline.
Process terminated. The type initializer for 'System.Management.Automation.PSObject' threw an exception.
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
   at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSObject' threw an exception.
 ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.

File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
   --- End of inner exception stack trace ---
   at System.Management.Automation.PSObject.get_Properties()
   at System.Management.Automation.HostUtilities.GetDollarProfile(String allUsersAllHosts, String allUsersCurrentHost, String currentUserAllHosts, String currentUserCurrentHost)
   at Microsoft.PowerShell.ConsoleHost.DoRunspaceInitialization(Boolean skipProfiles, String initialCommand, String configurationName, Collection`1 initialCommandArgs)
   at Microsoft.PowerShell.ConsoleHost.DoCreateRunspace(String initialCommand, Boolean skipProfiles, Boolean staMode, String configurationName, Collection`1 initialCommandArgs)
   at Microsoft.PowerShell.ConsoleHost.CreateRunspace(Object runspaceCreationArgs)
   at Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(String initialCommand, Boolean skipProfiles, Collection`1 initialCommandArgs, Boolean staMode, String configurationName)
   at Microsoft.PowerShell.ConsoleHost.Run(CommandLineParameterParser cpp, Boolean isPrestartWarned)
   at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)


### Error details

_No response_

### Environment data

```powershell
Unable to get this data since PowerShell can't be run.

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Nov 30, 2021
  2. added
    WG-Maintainers-Build
    Issue-Bug
    on Nov 30, 2021
  3. iSazonov commented on Nov 30, 2021

    @iSazonov
    Collaborator
  4. mthalman commented on Dec 1, 2021

    @mthalman
    Author

    Just to clarify the conditions for this issue:

    • It's specific to Alpine 3.15. It doesn't repro on Alpine 3.14.
    • It's specific to .NET 6. It doesn't repro on .NET 5.
  5. adityapatwardhan commented on Dec 1, 2021

    @adityapatwardhan
    Member

    We have not explicitly tested on Alpine 3.15 yet. I will have a look.

  6. mthalman commented on Dec 15, 2021

    @mthalman
    Author

    Aditya Patwardhan (@adityapatwardhan) - I've verified that this still doesn't work when using PowerShell 7.2.1/.NET SDK 6.0.101.

  7. adityapatwardhan commented on Dec 15, 2021

    @adityapatwardhan
    Member

    Let me have a look, it seemed to work in my testing. I might have missed something.

  8. mikeTWC1984 commented on Dec 16, 2021

    @mikeTWC1984
    Contributor

    I was installing pwsh7.2 (without sdk) on alpine3.15, using official instructions:
    https://docs.microsoft.com/en-us/powershell/scripting/install/install-alpine?view=powershell-7.2
    I have no any issue so far. Matt Thalman (@mthalman) - try to add all packages from this guide.

    As a side note - I'm looking forward to see official ps7.2 image for alpine 3.15

    Information about installing PowerShell on Alpine Linux
  9. mthalman commented on Dec 16, 2021

    @mthalman
    Author

    I was installing pwsh7.2 (without sdk) on alpine3.15, using official instructions:

    So you're installing directly from the tarball? Yes, that works. What doesn't work is installing as a global tool from the .NET SDK. The PowerShell deployment types are different between the two. The tarball contains a self-contained deployment of PowerShell while installing as a global tool is a framework-dependent deployment.

  10. deleted a comment from on Dec 16, 2021
  11. mthalman commented on Jan 12, 2022

    @mthalman
    Author

    Aditya Patwardhan (@adityapatwardhan) - We'd like to be able to ship .NET official container images for Alpine 3.15 for the February servicing release. But that depends on this being fixed. Is there enough time to get this addressed by then?

  12. heapifyman commented on Jan 12, 2022

    @heapifyman

    I get the same error message as Matt Thalman (@mthalman) on Manjaro Linux when installing pwsh as a global dotnet tool.

    dotnet --info                                                                                                                                                                                                                                                        
    .NET SDK (reflecting any global.json):
     Version:   6.0.100
     Commit:    9e8b04bbff
    
    Runtime Environment:
     OS Name:     manjaro
     OS Version:  
     OS Platform: Linux
     RID:         arch-x64
     Base Path:   /usr/share/dotnet/sdk/6.0.100/
    
    Host (useful for support):
      Version: 6.0.0
      Commit:  4822e3c3aa
    

    Steps to reproduce

    1. dotnet tool install --global powershell
    2. Open new terminal
    3. pwsh

    Result

    PowerShell 7.2.1
    Copyright (c) Microsoft Corporation.
    
    https://aka.ms/powershell
    Type 'help' to get help.
    
    One or more errors occurred. (The type initializer for 'System.Management.Automation.TypeAccelerators' threw an exception.)
    One or more errors occurred. (The type initializer for 'System.Management.Automation.TypeAccelerators' threw an exception.)
    Cannot load PSReadline module.  Console is running without PSReadline.
    Process terminated. The type initializer for 'System.Management.Automation.PSObject' threw an exception.
       at System.Environment.FailFast(System.String, System.Exception)
       at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
       at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])
    System.TypeInitializationException: The type initializer for 'System.Management.Automation.PSObject' threw an exception.
     ---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.
    
    File name: 'Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
       --- End of inner exception stack trace ---
       at System.Management.Automation.PSObject.get_Properties()
       at System.Management.Automation.HostUtilities.GetDollarProfile(String allUsersAllHosts, String allUsersCurrentHost, String currentUserAllHosts, String currentUserCurrentHost)
       at Microsoft.PowerShell.ConsoleHost.DoRunspaceInitialization(Boolean skipProfiles, String initialCommand, String configurationName, Collection`1 initialCommandArgs)
       at Microsoft.PowerShell.ConsoleHost.DoCreateRunspace(String initialCommand, Boolean skipProfiles, Boolean staMode, String configurationName, Collection`1 initialCommandArgs)
       at Microsoft.PowerShell.ConsoleHost.CreateRunspace(Object runspaceCreationArgs)
       at Microsoft.PowerShell.ConsoleHost.DoRunspaceLoop(String initialCommand, Boolean skipProfiles, Collection`1 initialCommandArgs, Boolean staMode, String configurationName)
       at Microsoft.PowerShell.ConsoleHost.Run(CommandLineParameterParser cpp, Boolean isPrestartWarned)
       at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText)
       at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)
    
  13. adityapatwardhan commented on Jan 18, 2022

    @adityapatwardhan
    Member

    The loading issue is related to .NET 6 missing RID for Alpine 3.15. Issue tracking it: dotnet/runtime#62938

    the change needs to go back to .NET 6.

  14. ghost removed
    Needs-Triage
    on Jan 18, 2022
  15. added
    Resolution-External
    on Jan 18, 2022
  16. heapifyman commented on Jan 19, 2022

    @heapifyman

    Aditya Patwardhan (@adityapatwardhan) I'm not using alpine but manjaro, and still get the same error. How does dotnet/runtime#62938 help me then?
    Should I open a separate issue?

  17. adityapatwardhan commented on Jan 19, 2022

    @adityapatwardhan
    Member

    Could be related. What specific version of manjaro do you see a problem with.

  18. heapifyman commented on Jan 19, 2022

    @heapifyman

    That would be the current Manjaro Gnome edition - as a rolling release there's no real version number.

    See also my previous comment

    OS: Manjaro Linux x86_64 
    Kernel: 5.15.12-1-MANJARO 
    Shell: zsh 5.8 
    DE: GNOME 41.2 
    WM: Mutter 
    Terminal: tmux 
    
    dotnet --info                                                                                                                          ✔ 
    .NET SDK (reflecting any global.json):
     Version:   6.0.100
     Commit:    9e8b04bbff
    
    Runtime Environment:
     OS Name:     manjaro
     OS Version:  
     OS Platform: Linux
     RID:         arch-x64
     Base Path:   /usr/share/dotnet/sdk/6.0.100/
    
    Host (useful for support):
      Version: 6.0.0
      Commit:  4822e3c3aa
    
    .NET SDKs installed:
      3.1.120 [/usr/share/dotnet/sdk]
      6.0.100 [/usr/share/dotnet/sdk]
    
    .NET runtimes installed:
      Microsoft.AspNetCore.App 3.1.20 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.AspNetCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
      Microsoft.NETCore.App 3.1.20 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
      Microsoft.NETCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
    
  19. jonstelly commented on Mar 4, 2022

    @jonstelly

    I'm getting the same error on Manjaro KDE. Notes:

    dotnet tool install of pwsh (7.2.1) = the above error
    aur powershell building from source (7.2.1) = failed test about base64 encoding
    aur powershell-bin (7.2.1-2) = pwsh works as expected

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

Metadata

Metadata

Labels

Issue-BugResolution-ExternalWG-Maintainers-Build

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions