gerardog/gsudo

Issue: Failed to load the hostfxr.dll, when PowerShell installed via Microsoft Store [v2.0.4]

mravalanche opened this issue · 10 comments

Similar to Issue 65, gsudo throws an error, failing to load hostfxr.dll when using PowerShell as installed from the Microsoft Store.

> gsudo
Failed to load the dll from [C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.1.0_x64__8wekyb3d8bbwe\hostfxr.dll], HRESULT: 0x80070005
The library hostfxr.dll was found, but loading it from C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.1.0_x64__8wekyb3d8bbwe\hostfxr.dll failed
  - Installing .NET prerequisites might help resolve this problem.
     https://go.microsoft.com/fwlink/?linkid=798306

Debug Output

Debug: Invoking Shell: PowerShellCore
Debug: Command Line: --debug
Debug: Applying workaround for target app installed via MSStore.
Debug: Command to run: C:\WINDOWS\system32\cmd.exe /v:on /s /c ""C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.1.0_x64__8wekyb3d8bbwe\pwsh.exe" -NoLogo"
Debug: Using Console mode TokenSwitch
Debug: Caller PID: 3900
Debug: Caller SID: S-1-5-21-834319090-4169696615-3995816478-1001
Debug: Elevating process: C:\Program Files (x86)\gsudo\gsudo.exe --debug gsudoelevate 3900 S-1-5-21-<SID>-1001 All 00:00:00
Debug: Service process started.
Debug: Found Named Pipe "ProtectedPrefix\Administrators\gsudo_0B46B6CBD3B3C594E81CFF1E631BD1CA1416D7870F0CACD865B7827155CA8CBC".
Debug: Connected via Named Pipe ProtectedPrefix\Administrators\gsudo_0B46B6CBD3B3C594E81CFF1E631BD1CA1416D7870F0CACD865B7827155CA8CBC.
Debug: CreateProcessAsUserWithFlags: C:\WINDOWS\system32\cmd.exe /v:on /s /c ""C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.1.0_x64__8wekyb3d8bbwe\pwsh.exe" -NoLogo"
Debug: Process token successfully substituted.
Failed to load the dll from [C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.1.0_x64__8wekyb3d8bbwe\hostfxr.dll], HRESULT: 0x80070005
The library hostfxr.dll was found, but loading it from C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.1.0_x64__8wekyb3d8bbwe\hostfxr.dll failed
  - Installing .NET prerequisites might help resolve this problem.
     https://go.microsoft.com/fwlink/?linkid=798306
Debug: Process exited with code -2147450750

Attempting to install .NET prerequisities via the given error link don't resolve the situation.
This occurs using both sudo and gsudo
Running with --attached also yields the same error

Service Output

Caller Pid: 6212
Running as:
  User: <COMPUTER>\<USER>
  Sid: S-1-5-21-<SID>-1001
  Is Admin: True
  Integrity Level: High (12288)

Credentials Cache:
  Mode: Explicit
  Available for this process: False
  Total active cache sessions: 0

Processes attached to the current console:
      PID      PPID Integrity  UserName                  Name
    12168      6212 High       <C>\<U>               C:\Program Files (x86)\gsudo\gsudo.exe (this gsudo status)

Info: Service started
Debug: Service will shutdown if idle for 00:00:10
Debug: Listening on named pipe ProtectedPrefix\Administrators\gsudo_0B46B6CBD3B3C594E81CFF1E631BD1CA1416D7870F0CACD865B7827155CA8CBC.
Debug: Access allowed only for ProcessID 3900 and children
Debug: NamedPipeServer listening.
Info: Incoming Connection.
Debug: ElevationRequest length 445
Debug: NtSetInformationProcess returned 0
Info: Connection Closed.
Debug: Listener Closed.
Info: Service stopped
Service shutdown. This window will close in 15 seconds

Context:

  • Windows version: 22H2
  • gsudo version: 2.0.4

Sorry to bring back an issue you've fixed previously :-(

Hi, have you looked at #106, where we found out powershell installation was corrupt?

  • Is your user a local admin or are you typing user & password at the UAC prompt?

  • Can you try: 'gsudo -d cmd' to elevate cmd first, then call "C:\Program Files\WindowsApps\Microsoft.PowerShell_7.1.4.0_x64__8wekyb3d8bbwe\pwsh.exe"?

  • Also, open cmd as admin (without gsudo) then run "C:\Program Files\WindowsApps\Microsoft.PowerShell_7.1.4.0_x64__8wekyb3d8bbwe\pwsh.exe"

Hi, have you looked at #106, where we found out powershell installation was corrupt?

Sorry, my bad on not checking that one out. I thought the closed issues were resolved, but I didn't clock that there wasn't a branch referenced in it.

Is your user a local admin or are you typing user & password at the UAC prompt?

I'm local admin, not elevating to a different user.

Can you try: 'gsudo -d cmd' to elevate cmd first, then call "C:\Program Files\WindowsApps\Microsoft.PowerShell_7.1.4.0_x64__8wekyb3d8bbwe\pwsh.exe"?
Also, open cmd as admin (without gsudo) then run "C:\Program Files\WindowsApps\Microsoft.PowerShell_7.1.4.0_x64__8wekyb3d8bbwe\pwsh.exe"

Okay, this was sensible. I'm on a different version of PowerShell than that (Microsoft.PowerShell_7.3.1.0_x64__8wekyb3d8bbwe) but I also get the same result in both circumstances:

# "C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.1.0_x64__8wekyb3d8bbwe\pwsh.exe"
Failed to load the dll from [C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.1.0_x64__8wekyb3d8bbwe\hostfxr.dll], HRESULT: 0x80070005
The library hostfxr.dll was found, but loading it from C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.1.0_x64__8wekyb3d8bbwe\hostfxr.dll failed
  - Installing .NET prerequisites might help resolve this problem.
     https://go.microsoft.com/fwlink/?linkid=798306

Is this a PowerShell issue, or an issue with the way that gsudo is installed (via winget for me)?

This is unrelated to gsudo. It seems your PowerShell install is corrupt, same as #106

You can try this:

  • Do not use gsudo. Open Comand Prompt as admin the old way. Type PWSH, press enter.
  • If the same error ocurrs, you have confirmation your Pwsh refuses to run as admin, and the issue has no relation to gsudo.
  • Create a ticket on https://github.com/PowerShell/PowerShell to find root cause/solution.

Or alternatively

Thanks for the help with this.
PWSH runs fine when called directly, and it appears that there are some descrepencies in paths for it.
The %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\pwsh.exe flavour works absolutely fine (which is default from cmd), but the %PROGRAMFILES% one as above causes the error.

No idea why this is the case, but as it is the case, this is not a gsudo problem, like you have said.

Thanks for your help. Debugging Windows weirdness is always a fun afternoon...

Mmm, I don't understand.
You say that if you run as admin: %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\pwsh.ex that one fails, but the %PROGRAMFILES% one works...
Why do you have two? Did you install Pwsh with several methods?
what do you get when you open CMD and type where pwsh ?
Or if you fixed this on your side please close the ticket
Thanks

I have also been getting this error for the last 2 days. It occurs only in my Windows Store PowerShell, not in my manually installed one. Seems to occur with 7.3.1 and 7.3.2. It occurs after a fresh install from the Store and even after rebooting.

Perhaps there is some Windows Store release practice not being respected by gsudo? As <7.3 MS Store worked with gsudo previously.

Note: Locally installed PowerShell works with gsudo in Windows Terminal and cmd. MS Store PowerShell does not work with gsudo in Windows Terminal or cmd. I am using chocolatey for gsudo.

Most likely an issue with the MS Store PowerShell release of hostfxr.dll or a permission change from execution to read only. Will try to investigate. Worked on my laptop with 7.3.2, updated Windows 10, now it is the same error.

Works for me using Powershell 7.3.2 from the store. Do exactly this and paste the differences.

image

Also, run cmd as admin, then run
C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.2.0_x64__8wekyb3d8bbwe\pwsh.exe
and paste the exact screenshot too.

Both screenshots, please.

terminal w/ store ps
image

image

terminal w/ manual ps can't get all of it in one SS since it cls's
image
image

image

cmd manual pwsh
image

cmd ms store ps
image

Can't even launch it from cmd, get the hostfxr error. Yet, WT can open it.

This is the ms store profile folder loc of pwsh (where windows terminal loads the pwsh from for the ms store pwsh)
C:\Users\Justin\AppData\Local\Microsoft\WindowsApps\Microsoft.PowerShell_8wekyb3d8bbwe
(where windows terminal loads pwsh from for the current version from the store, used in the first 2 screenshots)

which is not using the installed pwsh at:
C:\Program Files\WindowsApps\Microsoft.PowerShell_7.3.2.0_x64__8wekyb3d8bbwe
(where ms store saves apps?)

but this one works with gsudo (manually installed):
C:\Program Files\PowerShell\7\pwsh.exe

I apologize for not having time for gsudo lately.

I need your help to find out is this is a problem on gsudo or on powershell.
If your machine still has the problem, please do the following:

  1. Run cmd as admin with right click, then 'run as admin'. It is important you don't elevate using gsudo, so we can find if gsudo is part of the problem or not. Then

  2. run where pwsh to get a list of installed PowerShells.

  3. run each one, and paste the results here.
    For example:
    image


  • If any pwsh refuses to load, then that may be a problem with your computer or your Powershell install (because you elevated cmd without using gsudo). So it's not a problem in gsudo and you should ask the powershell team without mentioning gsudo. Gsudo is elevating properly but your powershell is broken. So far this has always been the case.
  • If every pwsh runs fine as admin, and you can only break it using gsudo, then fine it could be a something I should address.