Powershell: Start-Process: Unable to load DLL 'api-ms-win-core-job-12-1-0.dll'

Created on 4 Apr 2018  路  23Comments  路  Source: PowerShell/PowerShell

Repro:

Use clean install of Windows 7 SP1 (apparently both x86 and x64 are affected). Then run the following command in PS 6.0.2 ZIP version:

~
Start-Process "ipconfig" -ArgumentList "/flushdns" -Wait -NoNewWindow
~

Result:

~~~
Start-Process : Unable to load DLL 'api-ms-win-core-job-l2-1-0.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
At line:1 char:1

  • Start-Process -FilePath "C:7zip7za.exe" -ArgumentList ("x -oC:temp ...
  • ~~~~~~~~~~~~~~~~~
  • CategoryInfo : NotSpecified: (:) [Start-Process], DllNotFoundException
  • FullyQualifiedErrorId : System.DllNotFoundException,Microsoft.PowerShell.Commands.StartProcessCommand
    ~~~

PowerShell 6.0.2 x86 zip
Windows 7 b7601 SP1 x86 (modern.ie VM)

Works perfectly fine on Win10 x64.

Also tried 6.1.0-preview1, behaves the same way.

Area-Maintainers-Build Issue-Bug OS-Windows Resolution-Fixed

Most helpful comment

The fact that after almost 4 months this issue is still open indeed is puzzling. Win7 is officially supported, yet, PowerShell Core is completely broken on it. That means around HALF of your userbase. I'd recommend to either declare Win7 unsupported or fix this critical blocker.

But I can't just say to my users that "yeah, your OS is theoretically supported, except in practice it won't work". I can't say "a fix is in the works" either coz I haven't seen any _real_ activity on the matter.

All 23 comments

Actually, way easier to repro:

~
Start-Process "ipconfig" -ArgumentList "/flushdns" -Wait -NoNewWindow
~

Same on 6.1.0-preview1 x86. The user that reported this problem to me uses x64 tho, so apparently this issue affects both arches.

@gradinkov Please replace first repo with simple second in the issue description.

@mirichmo Could you please comment the Issue?

Sure thing, done!

The funny thing is that the commands actually run afterwards, just throw this exception first.

This is a problem when you run multiple commands in try-catch (as you normally should), which interrupts the rest of the try blocks and thus messes up execution.

TLDR if you run start-process in try-catch, anything that comes after start-process will be skipped.

@adityapatwardhan It looks like PowerShell Core needs another API set for Win 7. Do you know if there is a way to scan for compliance (static analysis) rather than checking at runtime?

The binary does not seem to be in the API set we use : runtime.win7-x64.Microsoft.NETCore.Windows.ApiSets/1.0.1. This needs further investigation.

I hit this on 6.0.1 on win7 x64.

$ $Error[0].exception.stacktrace

   at Microsoft.PowerShell.Commands.NativeMethods.CreateJobObject(IntPtr lpJobAttributes, String lpName)
   at Microsoft.PowerShell.Commands.ProcessCollection..ctor()
   at Microsoft.PowerShell.Commands.StartProcessCommand.BeginProcessing()
   at System.Management.Automation.Cmdlet.DoBeginProcessing()
   at System.Management.Automation.CommandProcessorBase.DoBegin()

@Arnavion Please test with lates PowerShell Core build https://github.com/PowerShell/PowerShell#build-status-of-master-branches

@iSazonov Same thing with current master GitCommitId: v6.1.0-preview.2-26-g84344cbb32ec5e2479e00394951832794bf37244

Unable to load DLL 'api-ms-win-core-job-l2-1-0.dll' or one of its dependencies: The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Microsoft.PowerShell.Commands.NativeMethods.CreateJobObject(IntPtr lpJobAttributes, String lpName)
   at Microsoft.PowerShell.Commands.ProcessCollection..ctor() in C:\Stuff\Sources\PowerShell\src\Microsoft.PowerShell.Commands.Management\commands\management\Process.cs:line 2551
   at Microsoft.PowerShell.Commands.StartProcessCommand.BeginProcessing() in C:\Stuff\Sources\PowerShell\src\Microsoft.PowerShell.Commands.Management\commands\management\Process.cs:line 2018
   at System.Management.Automation.Cmdlet.DoBeginProcessing() in C:\Stuff\Sources\PowerShell\src\System.Management.Automation\engine\cmdlet.cs:line 159
   at System.Management.Automation.CommandProcessorBase.DoBegin() in C:\Stuff\Sources\PowerShell\src\System.Management.Automation\engine\CommandProcessorBase.cs:line 499

@Arnavion Thanks for confirmation!

any news? this is completely blocking us 馃憥 i still havent found a workaround
we're running windows server 2008 r2

The fact that after almost 4 months this issue is still open indeed is puzzling. Win7 is officially supported, yet, PowerShell Core is completely broken on it. That means around HALF of your userbase. I'd recommend to either declare Win7 unsupported or fix this critical blocker.

But I can't just say to my users that "yeah, your OS is theoretically supported, except in practice it won't work". I can't say "a fix is in the works" either coz I haven't seen any _real_ activity on the matter.

Looking https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createjobobjecta
I guess we could directly reference Kernel32.dll

I found a workaround for the issue.

The issue is with -Wait. You can use -PassThru and wait for the process completion. Something like this:

$process = Start-Process "ipconfig" -PassThru -NoNewWindow 
Wait-UntilTrue -sb { $process.HasExited }

The function Wait-UntilTrue is defined here:
https://github.com/PowerShell/PowerShell/blob/master/test/tools/Modules/HelpersCommon/HelpersCommon.psm1#L3

@gradinkov @meekaah @Arnavion

Wait-UntilTrue : The term 'Wait-UntilTrue' is not recognized as the name of a cmdlet, function, script file, or... :( how are you using it? are you adding something else? Oh did you have to add that module manually and load it for it to work?

UPDATE: yeah i added the module manually and it does work as a workaround thanks a lot even if it is sort of a hack 馃憤

This error is slowing me down from moving From PowerShell to Core
This error happens on Server 2008 R2 but not on Windows 10 1709

The issue happens only then Start-Process using -Wait argument.
Start-Process creates ProcessCollection to monitor child processes which calls NativeMethods.CreateJobObject (https://github.com/PowerShell/PowerShell/blob/003a141f318fa1e79f7c19844298b3a6d33a5a76/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs#L2585).
"CreateJobObject" declared using pinvoke that points to "api-ms-win-core-job-l2-1-0.dll"(https://github.com/PowerShell/PowerShell/blob/003a141f318fa1e79f7c19844298b3a6d33a5a76/src/System.Management.Automation/utils/PInvokeDllNames.cs#L84).
According to unofficial info this api set was introduced in Windows 8 ( https://www.geoffchappell.com/studies/windows/win32/apisetschema/history/sets62.htm ).
For some strange reason this api set dll did not included in PowerShell distribution, but many other non "windows 7" api set dll were included.
So to fix this bug "api-ms-win-core-job-l2-1-0.dll" should be added to redistribute api set files list (https://github.com/PowerShell/PowerShell/blob/003a141f318fa1e79f7c19844298b3a6d33a5a76/assets/files.wxs#L74) (along with other api set mentioned in PInvokesDllNames)

Quick dirty fix: droping api-ms-win-core-job-l2-1-0.dll from "windows8/system32" installation to window7/PowerShell/6/ folder will solve issue

One and a half years ago and the issue is still present. Could you let us know what's the plan with this bug, please?

Windows 7 Ultimate 64-bit
PowerShell Core 6.2.2

:tada:This issue was addressed in #10417, which has now been successfully released as v7.0.0-preview.4.:tada:

Handy links:

:tada:This issue was addressed in #10417, which has now been successfully released as v6.2.4.:tada:

Handy links:

Was this page helpful?
0 / 5 - 0 ratings